![]() |
|
[Python] Beginner (Serious Beginner) and need help - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Beginner (Serious Beginner) and need help (/showthread.php?tid=4501270) |
Beginner (Serious Beginner) and need help - Messl - Oct 21, 2014 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 * - Dalek - Oct 21, 2014 (Oct 21, 2014 04:08 PM)Messl Wrote: radius = input("What is your radius value?: ") 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?: "))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. * - Messl - Oct 21, 2014 (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?: "))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. * - Dalek - Oct 21, 2014 (Oct 21, 2014 04:21 PM)Messl Wrote:What version of python are you using? That could be the problem. * - glob - Oct 21, 2014 PHP Code Need to convert the input to an integer. * - Dalek - Oct 22, 2014 (Oct 21, 2014 05:13 PM)glob Wrote:Already helped him with this mate. :) * - VybzKartel - Oct 22, 2014 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. * - SALMANIAC - Oct 22, 2014 radius = int(input("What is your radius value?: ")) area = 3.14*radius**2 print (area) Enjoy * - ℱuryッ - Oct 22, 2014 (Oct 22, 2014 04:45 PM)SALMANIAC Wrote: radius = int(input("What is your radius value?: ")) Dude... P.E.M.D.A.S. Order of operations. exponent first... * - glob - Oct 22, 2014 (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. Python has order of operations built in so it does it in that order anyway |