A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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")

  • This Question is Closed
  1. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the help

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  5. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    the i is capitalized in if

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  7. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  8. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  11. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  12. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    >>> >>> 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

  13. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  14. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  15. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  16. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  17. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    your welcome

  18. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.