Thread: Beginner

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    543
    Rep Power
    24

    Beginner


    I just started using Python today. So please excuse my "n00bish" questions.

    I have:
    Python 2.2.2
    Windows XP Home Edition.

    I was using this tutorial when I encountered my problem:
    http://www.hetland.org/python/instant-hacking.php
    (ctrl + f: Feedback)

    I was trying to do the "input" thing. I tried for the:

    radius = input("What is the radius?")

    print radius*radius*3.14



    temperature = input("What is the temperature of the spam?")

    if temperature > 50:
    print "The salad is properly cooked."
    else:
    print "Cook the salad some more."



    # Area calculation program

    print "Welcome to the Area calculation program"
    print "---------------------------------------"
    print

    # Print out the menu:
    print "Please select a shape:"
    print "1 Rectangle"
    print "2 Circle"

    # Get the user's choice:
    shape = input("> ")

    # Calculate the area:
    if shape == 1:
    height = input("Please enter the height: ")
    width = input("Please enter the width: ")
    area = height*width
    print "The area is", area
    else:
    radius = input("Please enter the radius: ")
    area = 3.14*(radius**2)
    print "The area is", area


    I got the following error:
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "<string>", line 0

    ^

    SyntaxError: unexpected EOF while parsing
    Last edited by MasterChief; June 9th, 2003 at 07:40 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    89
    Rep Power
    13
    hmm it works for me, are you sure you're properly indenting the code in the if-else sections?
  4. #3
  5. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    When you type in the values, are you putting them in quotation marks? Like this:

    What is the radius?
    "15"

    input() requires you to include quotation marks to create a proper string object. You can always use raw_input which doesn't.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69

    Mmmm..no?


    I have to disagree with you telex4, when runing Python on my machine, when entering numbers into input(), if you add quotation marks then the number it creates a str object not an int and so you can't add, subtrect or devide it ect.
  8. #5
  9. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    Ahh, I suppose I've never used input() for integers, and it always fails on strings. The advantages of having a python shell nearby...
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69

    Oops?


    Mmmm, I'm a lil comfused but hey. You know if you wana delete a post click edit and then delete post at the top of the edit page.

    Mark.

IMN logo majestic logo threadwatch logo seochat tools logo