Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

import random

a = random.randint(1, 20)

print("Enter your name: ")

name = input()

print("Choose an integer between 1 and 20")

for i in range(6):

guess = int(input("Enter a valid number "+name+": "))

if guess>20 or guess<0:

print("Invalid input")

print("Closing game")

break

elif guess == a:

if i == 0:

print("You have guessed the number correctly in first try")

else:

print("You have guessed the number correctly in ",(i+1), "tries")

print("You win")

break

elif guess>a:

print("You have chosen a bigger number")

print("You have ",(5-i)," chances left to guess the number")

elif guess<a:

print("You have chosen a smaller number")

print("You have ",(5-i)," chances left to guess the number")

if (5-i) == 0:

print("You lose")

You might also like