Question: I need help to my pygame assignment. Take the attached game1. py contents and copy it to a file named game1 asgn. py. Then make
I need help to my pygame assignment.
Take the attached game1. py contents and copy it to a file named game1 asgn. py. Then make the following changes:
1. Make all if statements more efficient by using elif and else whenever appropriate.
2. Combine the three lines immediately following the while statement into one (1) line of code.
3. Change all print statements so that conversion specifiers are used. Note: You should remove any type casts!
4. Add at least one more improvement. Please add a comment in your code to identify this improvement
This is the code.
#guessing game import random def main(): guesses = 0 randNum = random.randint(1,20) while guesses < 6: print("Please input a number:") myGuess = input() myGuess = int(myGuess) guesses = guesses + 1 if myGuess < randNum: print("Number is higher.") if myGuess > randNum: print("Number is lower") if myGuess == randNum: break if myGuess == randNum: guesses = str(guesses) print("Perfect, your got it in " + guesses + " guesses") if myGuess != randNum: print("Try again!") main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
