Post: [Python] Area of Circle Calculator
04-18-2011, 09:00 PM #1
vSaBoTeuR x
< ^ > < ^ >
(adsbygoogle = window.adsbygoogle || []).push({}); So, I got bored and I made this little application in Python that fully takes input from the command line. It's built for 2.6, because I don't agree with the changes in Python 3, and because I learned Python in 2.6.

Licensed under WTFPL.

Source Code:
    [color=#DD0000]#            DO WHAT THE **** YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar <[email protected]>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE **** YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE **** YOU WANT TO. [/color]

[color=#FF7700]from[/color] math [color=#FF7700]import[/color] pi
[color=#FF7700]from[/color] sys [color=#FF7700]import[/color] argv

script, radius = argv
r = [color=purple]float[/color](radius)
area = (r*r)*math.pi

[color=#FF7700]print[/color] "Area: %r cm2" % area

[color=#DD0000]# END OF SCRIPT[/color]


Parameters: (do not use the []'s)
python [name of script, ex. area.py] [radius in centimeters]
If anyone requires help with the param's, just say so and I'll make an overview.

That's basically it. Yes, I know this is useless, but who cares. It's Python, ya know! :carling:
(adsbygoogle = window.adsbygoogle || []).push({});

The following 2 users say thank you to vSaBoTeuR x for this useful post:

Outlasted Wolf, schnzrs
04-18-2011, 09:10 PM #2
schnzrs
Do a barrel roll!
Pretty cool how to implemented command line arguments in it. Sexy. Also, you don't need to comment out every line at the top.

You can do some thing like:
    """This is a 
multi-line comment
in Python"""

The following user thanked schnzrs for this useful post:

vSaBoTeuR x
04-18-2011, 09:14 PM #3
vSaBoTeuR x
< ^ > < ^ >
Originally posted by schnzrs View Post
Pretty cool how to implemented command line arguments in it. Sexy. Also, you don't need to comment out every line at the top.

You can do some thing like:
    """This is a 
multi-line comment
in Python"""


Thanks! You've got any other idea's I could use for an eventual next application?

About the triple-double-quotes;
I've read something about it in the Python mail list back in the day. But I preferred to comment the licensing out to make it more clear. But using triple-double-quotes (official name :lolSmile will also do the job.


~xNCK

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo