I am writing a game and I want a certain part of the code to redo. The comments in the code show what I want to redo.
import random
def getRandom():
#this is the code I want to rerun (guess code) but I don't want to reset "players" and "lives"
players = 10
lives = 5
myGuess = input("What number do you choose")
compGuess = random.randint(1,5)
compGuess = int(compGuess)
print(f"Computer chose {compGuess}")
if compGuess == myGuess:
players = players - compGuess
print(f"You took out {compGuess} players")
print(f"There are {players} players left")
#run guess code
else:
lives -= 1
print(f"You lost a life! You now have {lives} lives remaining")
#run guess
getRandom()