Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 9 Online
OpenStudy (anonymous):

Hi i am wondering what i did wrong here- def ask() : answer = raw input("Do you wish to tell me about your favorite desert?") If (answer == 'yes' ) : print ("Next i will ask you about your favorite desert") Print ("now i will tell you about your clasess favorite desert")

OpenStudy (mattc):

you have a few syntax errors, raw input has to be raw_input, you can not capitalize if or print.

OpenStudy (mattc):

you can see syntax errors when you try and run the program, they should highlight in red, and as you fix each error it will point out another.

OpenStudy (anonymous):

Thanks for the help

OpenStudy (anonymous):

i have a syntax error that im not sure how to resolve If (answer == 'yes' ) : print ("Next i will ask you about your favorite desert") The colon is the line is having a syntax problem and im not sure what is wrong, thanks

OpenStudy (mattc):

the i is capitalized in if

OpenStudy (anonymous):

yeah it is, but im getting a snytax eorr on the colon

OpenStudy (mattc):

where it points unfortunately is not always 100% accurate, its close but the error may be somewhere else on that line or even another place entirely, python is case sensitive.

OpenStudy (mattc):

so it will not recognize If,Else,Return it will recognize if, else, return

OpenStudy (anonymous):

ok i fixed the syntax, now when i go to run the module it will run and nothing happens (im a beginner)

OpenStudy (anonymous):

im not sure if i just need to add something to the end of the script,

OpenStudy (mattc):

so now you have a working program. cool but what you have written so far is a function. A function will not do anything unless you have called it somewhere. you can simply call it by typing ask() anywhere after the function has been defined. So you can not call ask() before you have defined the function ask(), later on in this course there are instances where a function will call itself within itself. Dont worry about that yet.

OpenStudy (anonymous):

>>> >>> ask () Do you wish to tell me about your favorite desert?yes Next i will ask you about your favorite desert Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> ask () File "C:\Python25\fixedhw.py", line 4, in ask Print ("now i will tell you about your clasess favorite desert") NameError: global name 'Print' is not defined This is the error im getting when i call the function

OpenStudy (mattc):

its another syntax error, try and find out what it is, and if you still need help let me know

OpenStudy (anonymous):

ok i found it, thank you very much youv been a great help, now im wondering about this, i am trying to mkae the program do=that asks the user whether they wish to tell which is their favorite dessert, or they wish to find out what other's favorite dessert is. Now when i do that i prints both the lines at the end regardless if they say yes or no, so im wondering how to seprate them and make it only print depending on the awnser the user gives.

OpenStudy (mattc):

take a look at this. http://docs.python.org/tutorial/controlflow.html

OpenStudy (anonymous):

ok perfect, thanik you very much. i might be back with more questions :) but thanks for now

OpenStudy (mattc):

your welcome

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!