Function 当有两个输入时,如何获得函数输入,而不是主体输入

Function 当有两个输入时,如何获得函数输入,而不是主体输入,function,while-loop,Function,While Loop,这是我的代码,这里引用的是版权 艾尔·斯维加特。用Python发明你自己的电脑游戏。2015年8月28日。于2020年12月4日查阅 #import modules import random import time #def functions def intro(): guess = int(input("There are two caves, in one is magic treasure and in the other is a terrible monste

这是我的代码,这里引用的是版权 艾尔·斯维加特。用Python发明你自己的电脑游戏。2015年8月28日。于2020年12月4日查阅

#import modules
import random
import time

#def functions
def intro():
    guess = int(input("There are two caves, in one is magic treasure and in the other is a 
terrible monster. Hit 1 or 2 to guess. "))
    return guess


def check_cave(guess):
    print("the cave is dank")
    time.sleep(2)
    print("you hear a sound")
    time.sleep(2)
    print("a monster jumps out and opens its jaws and...")
    time.sleep(2)

    friendly_cave = random.randint(1,2)
    if str(guess) == str(friendly_cave):
        print("leaves so you can take the treasure, congratulations!")
    else:
        print("kills you bahahaha")
        print(guess)

#main body of code
play_again = 'no'
guess = int(input("please enter a guess of one or two "))
while play_again == 'yes' or 'y':
    intro()
    check_cave(guess)
    play_again = input("want to play again? yes or no...")
    if play_again == 'yes':
        continue
    else:
        break

我希望代码从代码主体请求用户输入,然后从函数内部请求相同的输入(函数返回输入),我希望函数的返回值覆盖原始输入。但事实并非如此。相反,它保留了函数外部的原始输入。对此,我能做些什么?

您必须将函数
intro()返回的值赋值给变量:

while play_再次=='yes'或'y':
guess=intro()#修改了这一行
检查洞穴(猜测)
再次播放=输入(“想再次播放吗?是或否…”)
如果再次播放=是:
持续
其他:
打破

我现在意识到,我所说的“check_cave(guess)是函数,没有消失的值是guess=int(输入(废话))