In: Computer Science
(Python code please) Of a Guessing game(1-10) with a limited amount of guesses (5)
Program Code Screenshot:
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to
copy:
import random
c=0
f=0
while c<5:#loop 5 times
c+=1
n=int(input("Enter your guess(1-10)"))#read input from user to
guess
r=random.randint(1,10)#check a random number
if n==r:#check if numbers are same
print("Congratulations! You took ",c," attempts to guess")
f=1
break
else:
print("Try again!")
continue
if f==0:
print("Sorry! you did not guess!")
Note:
Please let me know in case of any help needed in the comments section.
Plese upvote my answer. Thank you.