0% found this document useful (0 votes)
60 views1 page

Guess Game

The program generates a secret number between 1 and 20. It allows the player, whose name is input, 6 chances to guess the number. For each guess, it tells the player if the guess is correct or not and how many chances remain. If the player does not guess correctly in 6 tries, it tells them their chances are over.

Uploaded by

jj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

Guess Game

The program generates a secret number between 1 and 20. It allows the player, whose name is input, 6 chances to guess the number. For each guess, it tells the player if the guess is correct or not and how many chances remain. If the player does not guess correctly in 6 tries, it tells them their chances are over.

Uploaded by

jj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

2.

a) Guess the Number: Write a program that tells the player that it has come up with
a secret number and will give the player six chances to guess it. The code that lets the
player enter a guess and checks that guess is in a for loop that will loop at most six
times.

number=18

print('Welcome to guess game,Enter your name to get started with.')

Name=str(input())

print('Welcome',Name, 'You can guess a number between 1 and 20 and you will get six chances to
guess that number')

i=6

for i in range(6,0,-1):

print("Enter your guess:")

guessed_number=int(input())

if guessed_number==number:

print('Wow Congratulations!, Your guess is correct.')

break

else:

print('try again!,you have '+ str(int(i-1)) + ' chances left')

i=i-1

continue

if i==0:

print('Thank You..Your chances are over..better luck next time')

You might also like