I need help adjusting code already written to incorporate some other factors,
Question
I need help adjusting code already written to incorporate some other factors,
style=”color:rgb(45,59,69);”>I need to add a list that keeps track of all the numbers guessed and modularizes the code.
I also need to be able to input a number and see if the computer can guess it.
Below is the code I need to add the items to.
Please assist!
import random
Name=input(“Name: “)
Date=input(“Date: “)
def numberGuessingGame(myGuess, num):
if myGuess > num:
print(‘Too high’)
elif myGuess < num:
print(‘Too low’)
def main():
print(‘Welcome to my Guess the number program!’)
num = random.randint(1, 10)
count=0
while True:
print(‘nWho will guess the number?n1.Usern2.Computer’)
choice=input(‘=> ‘)
if choice==’1’:
guess_num=int(input(‘Please guess a number between 1 and 10: ‘))
numberGuessingGame(guess_num,num)
count=count+1
elif choice==’2’:
guess_num = random.randint(1, 10)
numberGuessingGame(guess_num,num)
count=count+1
else:
print(‘Wrong choice!’)
if guess_num == num:
print(‘You guessed it! It took’,count, ‘attempts’)
break
main()