Python 如何为我的脚本赋予用户5条生命?

Python 如何为我的脚本赋予用户5条生命?,python,computer-science,python-3.9,Python,Computer Science,Python 3.9,标题。 我目前正在为我的计算机科学课程编写一个choose your own adventure python脚本,需要给玩家5条生命,当他们用完时,会出现一行文本。有什么想法吗 (我不确定是否需要发布脚本,但如果需要,我可以在今天晚些时候发布。) 脚本: # Name: Drew Dilley **# Date: 12/7/20 # 1 REMOVED IMPORT MATH BECAUSE IT IS NOT NEEDED FOR THIS SCRIPT. # 2 import random

标题。 我目前正在为我的计算机科学课程编写一个choose your own adventure python脚本,需要给玩家5条生命,当他们用完时,会出现一行文本。有什么想法吗

(我不确定是否需要发布脚本,但如果需要,我可以在今天晚些时候发布。)

脚本:

# Name: Drew Dilley
**# Date: 12/7/20
# 1 REMOVED IMPORT MATH BECAUSE IT IS NOT NEEDED FOR THIS SCRIPT.
# 2
import random
answer: str = input("Do you want to go on an adventure? (Yes/No)")
# hint: the program should convert player's input to lowercase and get rid of any space player enters
# hint: check out what .upper(), .lower(), .strip() do on a string, reference: https://www.w3schools.com/python/python_ref_string.asp
# 3
if answer.upper().strip() == "yes":
    # hint: pay attention to the variable name
    # 4
    ANSWER= input("You are lost in the forest and the path splits. Do you go left or right? (Left/Right) ").lower().strip()
    if answer == "left":
        # 5 UNNECESSARY INDENT
        answer = input("An evil witch tries to cast a spell on you, do you run or attack? (Run/Attack) ").lower().strip()
    if answer == "attack": #(HAD TO FIX UNEXPECTED INDENT)
            print("She turned you into a green one-legged chicken, you lost!")
        # 6 HAD TO ADD PARENTHESES AND FIX THE SEMICOLON AFTER "ANSWER"
    elif answer := "run":
            print("Wise choice, you made it away safely.")
            answer = input("You see a car and a plane.  Which would you like to take? (Car/Plane) ").lower().strip()
    if answer == "plane":
                print("Unfortunately, there is no pilot. You are stuck!")
    elif answer == "car":
                print("You found your way home. Congrats, you won!")
            # 7 SEMICOLON NEEDED AFTER "ELSE" PLANE/ANSWER + CAR/ANSWER NEEDED TO BE FLIPPED. NO INDENTATION NEEDED FOR "ELSE". == INSTEAD OF !=
    elif answer != "plane" or answer != "car":
            print("You spent too much time deciding...")
    elif "right" != answer:
        else:
    print("You are frozen and can't talk for 100 years...")
# hint: the program should randomly generate a number in between 1 and 3 (including 1 and 3)
# hint: remember random module? reference: https://www.w3schools.com/python/module_random.asp
# 8 HAD TO IMPORT "RANDOM"
        num: int = random.randint(0,3)
        # 9
    answer = input("Pick a number from 1 to 3: ")
        # hint: will the following if statement ever be executed even when the values of answer and num are the same? If not, can you fix the problem?
        # hint: the error is not necessarily in the line below.
    if answer == num:
        print("I'm also thinking about {}".format(num))
        print("You woke up from this dream.")
    else:
        print("You fall into deep sand and get swallowed up. You lost!")
    else:
        print('You can\'t run away...')
# 10 NEEDED A SEMICOLON FOLLOWING THE ELSE STATEMENT, SO THAT IT KNOWS WHAT TO READ AND PERFORM NEXT IN THE SCRIPT.
else:
    print ("That's too bad!")** ```

您可以将for循环与计数器变量一起使用,每次播放器松开时,计数器变量可以递减,当它从5变为0时,您可以使用break退出循环,或使用break前打印来显示消息。

请提供您现有的代码,以便我们可以帮助您。有无数种方法可以实现你要做的事情,如果没有上下文,除了一般性的建议外,不可能给出任何东西。我添加了脚本:)这听起来会很好,但我不确定如何执行编写这样一个脚本,你能给我举个例子吗?