I need help expanding the following Python code.
I need help expanding the following Python code.
I need help
in adding an option for the computer to guess as well as the user to guess a number.
I also need to add a menu system.
In case I missed it, I need it to import random at the beginning of the code and use a comment block explaining what the program does
Here’s what I have now.
while(player > 0):
num = random.randint(1, 10)
player = numberGuessingGame(num)
if player == num:
break
def numberGuessingGame(num):
highCount = 0
lowCount = 0
print(‘Welcome to my Guess the number program!’)
myGuess = int(input(‘Please guess a number between 1 and 10: ‘))
while myGuess > 0:
if myGuess > num:
print(‘Too high’)
myGuess = int(input(‘Please guess a number between 1 and 10: ‘))
highCount +=1
elif myGuess < num:
print(‘Too low’)
myGuess = int(input(‘Please guess a number between 1 and 10: ‘))
lowCount +=1
else:
print(‘You guessed it! It took you ‘,(highCount+lowCount), ‘ attempts’)
return myGuess
return myGuess
main()