-2

I am trying to make a memory game in python 2.7.7 i need some help with My Code.

Guess1_Easy_Removed = raw_input("Which Word Do You Think Was Removed?:")
if Guess1_Easy_Removed == wordList[9]:
    print "Correct!"
else:
    print "Try Again!"
Guess2_Easy_Removed = raw_input("Which Word Do You Think Was Removed?:")
if Guess2_Easy_Removed == wordList[9]:
    print "Correct!"
else:
    print "Try Again!"
Guess3_Easy_Removed = raw_input("Which Word Do You Think Was Removed?:")
if Guess3_Easy_Removed == wordList[9]:
    print "Correct!"
else:
    print "Try Again!"

Guess1_Easy_Substitute= raw_input("Which Word Do You Think Was The Substitute Word?:")
if Guess1_Easy_Substitute == wordList[5]:
    print "Correct!"    
else:
    print "Try Again!"

Guess2_Easy_Substitute= raw_input("Which Word Do You Think Was The Substitute Word?:")
if Guess2_Easy_Substitute == wordList[5]:
    print "Correct!"
else:
    print "Try Again!"
Guess3_Easy_Substitute= raw_input("Which Word Do You Think Was The Substitute Word?:")
if Guess3_Easy_Substitute == wordList[5]:
    print "Correct!"
else:
    print "Try Again!"

The things i need help with are : if the user guesses the removed or substitute word right all other guesses should be stopped. if Removed & substitute words guessed correctly i need to , print "You win" do i need to use the break statement? Thanks

Paco
  • 4,520
  • 3
  • 29
  • 53

2 Answers2

0

I am hoping the indentation issues in your code is just a copy/paste mistake, otherwise the program would not be running at all. If your code runs inside a loop (like a for loop or while loop) , then you can use break statement to exit out of the loop.

Example of loop -

while True:
    Guess1_Easy_Removed = raw_input("Which Word Do You Think Was Removed?:")
    if Guess1_Easy_Removed == wordList[9]:
        print "Correct!"
        break    # <------- This would transfer the control out of the loop.
    else:
        print "Try Again!"
    ...... # you will need to do the break for all such scenarios.

If you are not using loops, and then you can use sys.exit(0) ( 0 indicates a successful run of the program) , for this you would need to import the sys module to the program , before using sys.exit() . This would cause the program to end.

Example -

import sys
Guess1_Easy_Removed = raw_input("Which Word Do You Think Was Removed?:")
if Guess1_Easy_Removed == wordList[9]:
    print "Correct!"
    sys.exit(0)    # <------- This would cause the program to end.
else:
    print "Try Again!"
...... # you will need to do the break for all such scenarios.
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
0

This is one way to do it:

Guess1_Easy_Substitute= raw_input("Which Word Do You Think Was The Substitute Word?:")
while Guess1_Easy_Substitute != wordList[5]:
    Guess1_Easy_Substitute= raw_input("Try again! Which Word Do You Think Was The Substitute Word?:")
    if Guess1_Easy_Substitute == wordList[5]:
        print "You win"
Joe T. Boka
  • 6,554
  • 6
  • 29
  • 48