a. Your program generates a random number between 0 and 128 and keeps asking the user to guess the number until the user guesses it correctly. b. If the user guesses a number that is lower or higher than the number to be guessed then indicate that information to the user as a ‘low guess’ or a ‘high guess’ so that the user can get to the correct guess quicker. c. The program keeps track on number of guesses taken by the user to get to the correct guess. This is user’s score. d. Your program asks user for the name and adds user’s name and the score in a file that keeps track of the scores by various users. e. At the end of the game, the program displays the top 3 scores (lowest 3 scores) along with the name of the users to conclude the game. John 4 Sam 7 Tony 10

Respuesta :

Answer:

import random

arr=[]

frr=open("score.txt","w")

for i in range(128):

   arr.append(i)

def func1(lst):

   score=0

   name=input("enter your name: ")

   while True:

       answer=random.choice(arr)  

       guess=int(input("enter your guess number between 0-128: "))

       if answer is guess:

           print("right guess\ncongratulations.....")

           print("the answer was: "+str(answer))

           score+=1

           break

       elif guess < answer-20:

           print("you guessed too low....\ntry again")

           print("the answer was: "+str(answer))

       elif guess > answer+20:

           print("you guessed too high....\ntry again")

           print("the answer was: "+str(answer))

       else:

           print("incorrect guess\ntry again")

           print("the answer was: "+str(answer))

       ext=int(input("press 0 to exit:\npress 1 to continue: "))

       if ext is 0:

           break

       

   return "{} {}".format(name,score)

num=int(input("how many users will be taking part: "))

for i in range(num):

   frr.write("{}\n".format(func1(arr)))

frr.close()

frr1=open("score.txt","r")

line=frr1.readline()

while line:

   print(line)

   line=frr1.readline()          

frr1.close()    

Explanation:

this code is in python3 language

it is displaying the name and the score, you just need to adjust the top 3 scores and least 3 scores.