We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,858 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Please help! Repeating

Okay. I am creating a program for school and I am a beginner to python. Here is my code:

intro = input("Want to play a game of number guess? ")

    while intro == 'yes':
        print("\nOkay. Just guess the number I am thinking of from 1 to 10.)
        if intro != 'yes' or 'no':
            print("\nThat command is not in my program. Try again: ")
            intro = input()  #This is supposed to let you retype your answer to the question if you did not type in no or yes
        if intro == 'no':
            choice = exit()  

    slot = input("\nInsert 50 cents into the coin slot to start. ")
    while slot != 'insert coin' or 'insert' or 'insert coins':
        print("What are you trying to do? Try again: ")
        slot = input()
        if slot  == 'insert':
            print("What are you inserting?")
            slot = input()
        if slot == 'insert coin':
            print("Quit trying to nickle and dime me! \nTWO coins (two quarters = 50 cents - duh)")
            slot = input()
        if slot == 'insert coins':
            print("\a\a\aBING BING BING!! Thank you for playing Jessica's Number \nGame. We will start in: \n3")
            print("2")
            print("1")
            print("....GO!! \nYou have: ", points,"points")


    guess = int(input("\nEnter your guess: "))

So what I need help with is that when I type in a wrong answer to the yes or no question in the beginning it's supposed to let you know that you have to write yes or no and it lets you type it in until you get it right and when you type yes or no the program restarts all over again and wont go to the next section. Can someone help me with this? (sorry i didn't know how to explain it well)

2
Contributors
1
Reply
1 Hour
Discussion Span
2 Years Ago
Last Updated
2
Views
Question
Answered
ijessiichan
Newbie Poster
1 post since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Use a while() loop that checks for the answer. Also, you should print what options are available as an answer instead of making the enterer guess. This is not intended as a complete answer.

while intro not in ["yes", "no"]:
    intro = input("Want to play a game of number guess? ('yes' or 'no'")

available_guesses = [str(x) for x in range(1, 11)]
while intro == 'yes':
    guess = "0"
    while guess not in available guesses:
        guess = input("\nOkay. Just guess the number I am thinking of from 1 to 10. ")
    while intro not in ["yes", "no"]:
        intro = input("Want to play a game of number guess? ('yes' or 'no'")

(sorry i didn't know how to explain it well)

That is why you can't code it. You have to first explain it in words, in detail, in order to explain it in code?

woooee
Posting Maven
2,705 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9
Question Answered as of 2 Years Ago by woooee

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0570 seconds using 2.68MB