The program below asks the user to enter how many lives they have left in a game. Your code should respond to the user's input as follows.
First, always display the message "You have X lives left." where X is the numLives value entered by the user.
Then, using if / elif / else logic:
If the number of lives is greater than or equal to 3, display the message "You should keep playing." Use the greater-than-or-equal-to (>=) operator.
Else if the number of lives is greater than 0, display the message "You should be careful". Use the greater-than (>) operator.
Else display the message "Game over".
After the first output line, your program will only display one of the middle three lines, based on the value of the livesNum variable.
The following examples demonstrate the expected program output.
How many lives do you have left in the game? 5
You have 5 lives left.
You should keep playing.
How many lives do you have left in the game? 0
You have 0 lives left.
Game over.
How many lives do you have left in the game? 2
You have 2 lives left.
You should be careful.
livesNum = int(input("How many lives do you have left in the game? "))
print("You have", livesNum, "lives left.")
# student code here
7 answers
print("You have", livesNum, "lives left.")
if livesNum >= 3:
print("You should keep playing.")
elif livesNum > 0:
print("You should be careful.")
else:
print("Game over.")
```
livesNum = int(input("How many lives do you have left in the game? "))
print("You have", livesNum, "lives left.")
if livesNum >= 3:
print("You should keep playing.")
elif livesNum > 0:
print("You should be careful.")
else:
print("Game over.")
```
Please let me know if you have any further questions.
```
numLives = int(input("How many lives do you have left in the game? "))
print("You have", numLives, "lives left.")
if numLives >= 3:
print("You should keep playing.")
elif numLives > 0:
print("You should be careful.")
else:
print("Game over.")
```
This code should now produce the expected output. Let me know if you have any further questions.
```python
livesNum = int(input("How many lives do you have left in the game? "))
print("You have", livesNum, "lives left.")
if livesNum >= 3:
print("You should keep playing.")
elif livesNum > 0:
print("You should be careful.")
else:
print("Game over.")
```
The code above uses the correct variable name, `livesNum`, as specified in the instructions. Let me know if you have any further questions.