game100.py

Created by cesphoto

Created on April 13, 2023

564 Bytes

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) 

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.