Six tries to guess a number between 1 and 100 (or other value) start() begins the game for 1 to 100 start(50) starts the game for 1 to 50
from random import * def start(m=100): val = randrange(1,m+1) x = -1 n = 0 print("Guess a number between 1 and " + str(m) + ".","You have 6 tries." ) while (x != val) and (n < 6): n = n+1 print() print("Enter guess #"+str(n)+":") x = int(input()) if x < val and (n != 6): print("too low") if x > val and (n != 6): print("too high") if x == val: print("Yeay!! You guessed it in",n,"tries.") if (n==6) and (x != val): print("You lost. The number was", val)