Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can someone write this out so i can copy and paste it to python? thank you guess.py 1 2 3 from random import randint import
can someone write this out so i can copy and paste it to python?
thank you
guess.py 1 2 3 from random import randint import os def play(): print(" \t::Guess Game: :") name = input("Enter Name: ") num = randint(1,100) guess_left = 4 passed = False print("Hi ", name, "! Lets Play! ", sep='') # print("The Number is", num) while guess_left>0: guess = int(input("Guess ("+str(guess_left)+" Tries Left): ")) if guess == num: print("Correct!") passed = True break elif guess>num: print("Too High!") else: print("Too Low!") guess_left-= 1 else: print("Failed! The Number was", num) print() if passed: save_high_score(name,guess_left) 27 def save_high_score(name, score): highs - () if os.path.isfile( 'highscore.txt'): fh = open('highscore.txt', 'r') highs = list(map(lambda x: x.strip(), fh.readlines())), fh.close() highs.append(str(score)+", "+name) highs = sorted (highs, key=Lambda x:x[1]) highs = sorted (highs, key=lambda x:x[0], reverse=True) fh = open('highscore.txt', 'w') for h in highs[:3]: fh.write(h+' ') fh.close() def show high score(): highs = [] if os.path.isfile( 'highscore.txt'): fh = open('highscore.txt', 'r') highs = list(map(lambda x: x.strip().split(','), fh.readlines())), fh.close() print(" \t::High Scores::") if len(highs)==0: print("No High Scores Yet!") else: print("Name\tScore") for h in highs: print("\t'.join(h[::-1])) 53 def main(): while True: print(" ENTER 1 to Play") print("ENTER 2 to Check High Scores") print("ENTER O to Exit") ch = input("Enter Choice (0-2): ") if ch=='0': break elif ch=='2': show_high_score() elif ch=='l': play() print() print("\t::THANK YOU:: ") 68 if ==' main ": name main()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started