Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Beginner (Serious Beginner) and need help

radius = input("What is your radius value?: ")
area = 3.14*radius**2
print (area)

Was given a beginners assignment to create a code that lets you calculate the area of a circle, Can someone please tell me where I am going wrong? If you can explain please.


Bump. Can anyone please help me? (Would mean alot)

It's Python btw sorry
Hi
(Oct 21, 2014 04:08 PM)Messl Wrote:  radius = input("What is your radius value?: ")
area = 3.14*radius**2
print (area)

Was given a beginners assignment to create a code that lets you calculate the area of a circle, Can someone please tell me where I am going wrong? If you can explain please.

I believe it's not working because the syntax for a manual input is raw_input() and not input().

Code
R = int(raw_input("What is your radius?: "))
area = 3.14 * (R*R)
print area

Here's a line by line explanation if you want it:
R = int(raw_input("What is your radius?: ")) This line asks the user for the radius and then makes it an integer using the int().
area = 3.14 * (R*R) This line does the calculations and saves it to a variable which we call area
print area This line simply prints out the area.
(Oct 21, 2014 04:17 PM)Dalek Wrote:  I believe it's not working because the syntax for a manual input is raw_input() and not input().

Code
R = int(raw_input("What is your radius?: "))
area = 3.14 * (R*R)
print area

Here's a line by line explination if you want it:
R = int(raw_input("What is your radius?: ")) This line asks the user for the radius and then makes it an integer using the int().
area = 3.14 * (R*R) This line does the calculations and saves it to a variable which we call area
print area This line simply prints out the area.

Code
R = int(raw_input("What is your radius?: "))
NameError: name 'raw_input' is not defined

This is the error I get for it. The original error was The brackets after print but i corrected that. Now it gives me this, any ideas? Btw it's python.
Hi
(Oct 21, 2014 04:21 PM)Messl Wrote:  
Code
R = int(raw_input("What is your radius?: "))
NameError: name 'raw_input' is not defined

This is the error I get for it. The original error was The brackets after print but i corrected that. Now it gives me this, any ideas? Btw it's python.
What version of python are you using? That could be the problem.
PHP Code

<?php 
radius 
= int(input("What is your radius value?: "))
area = 3.14*radius**2
print (area) 

Need to convert the input to an integer.
(Oct 21, 2014 05:13 PM)glob Wrote:  
PHP Code

<?php 
radius 
= int(input("What is your radius value?: "))
area = 3.14*radius**2
print (area) 

Need to convert the input to an integer.
Already helped him with this mate. :)
def circumferenceOfCircle():
r = eval(input("Enter Radius:"))
print (format(2*math.pi*r, ".2f"))

def areaOfCircle():
r = eval(input("Enter Circumference"))
print (format(math.pi*r*r, ".2f"))

first one is circumferenceOfCircle second one is areaOfCircle, instead of using int(input( you can also use eval which will evaluate the type of what the user inputs. The format .2f just makes it have 2 decimal spaces.
Light travels faster than sound, which is why some people may appear bright until you hear them speak
radius = int(input("What is your radius value?: "))
area = 3.14*radius**2
print (area)

Enjoy
(Oct 22, 2014 04:45 PM)SALMANIAC Wrote:  radius = int(input("What is your radius value?: "))
area = 3.14*radius**2
print (area)

Enjoy

Dude... P.E.M.D.A.S. Order of operations.

exponent first...
(Oct 22, 2014 05:59 AM)Dalek Wrote:  Already helped him with this mate. :)

No, actually you royally fucked up by assuming he was using Python 2.x and gave him an incorrect solution.

I gave a working 3.x solution


(Oct 22, 2014 04:49 PM)ℱuryッ Wrote:  Dude... P.E.M.D.A.S. Order of operations.

exponent first...

Python has order of operations built in so it does it in that order anyway