[Tutor] Beginner level: Why doesn't my code work?

Rafael Knuth rafael.knuth at gmail.com
Sun May 19 15:04:32 CEST 2013


Hello,

here's a tiny little program I wrote:

import random

print("""

This is a magic super computer.

He will ask you a couple of questions.

An ultra-complicated algorithm will then figure out what your favorite meal
is.

""")

name = str(input("What is your name? "))

age = int(input("How old are you? "))

birthplace = str(input("Where are you born? "))

meal = random.randint(1, 3)

if meal == 1:
    print("Well, " + name + " as a " + str(age) + " year old human being
born in " + birthplace + " you probably like hamburgers.")

elif meal == 2:
    print("Well, " + name + " as a " + str(age) + " year old human being
born in " + birthplace + " you probably like sushi.")

elif meal == 3:
    print("Well, " + name + " as a " + str(age) + " year old human being
born in " + birthplace + "you probably like pizza.")

Here's the error message I am getting:

Traceback (most recent call last):
  File "/home/rafael/Documents/3_Tufcik.py", line 13, in <module>
    name = str(input("What is your name? "))
  File "<string>", line 1, in <module>
NameError: name 'Rafael' is not defined


Can anyone help?
Thanks in advance!

Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130519/cbdb1c9e/attachment.html>


More information about the Tutor mailing list