I am making a simple python game. I would like to be able to restart the game based on user input. You have a certain amount of guesses to guess which way to coin falls. If you lose you would get the option of restarting, instead of just breaking the code. Also the program will not print "you lose". And I can not figure out why.
Thanks

import random
import sys
import os

print "You may press q to quit at any time"
print "You have six chances"
guess = 5
while guess >= 0:
    chance = random.choice(['heads','tails'])
    person = raw_input(" heads or tails: ")
    
    if person == 'q':
         print " Nooo!"
    if person == 'q':
        break   
    if person == chance:
        print "correct"
    elif person != chance:
        print "Incorrect"
        guess -=1
    elif guess == 0:
        print "you lose"
        break

Recommended Answers

All 2 Replies

Never mind, for I have learned of the continue statement.

Yeah you can use the while True loop around your current loop and use continue and break to control the game.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.