我的基于文本的python3游戏的RNG

2024-06-11 16:38:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新的编程和测试自己,我试图使一个文本为基础的游戏。问题是,在对话的选择中,我加入了一个基于RNG的语音检查,但我就是做不好。我很抱歉,如果这是一个愚蠢的问题,但我真的迷路了。你知道吗

以下是代码部分:

def scene1part2():
    option2 = ["1. Okay. Here you go you cheeky guard.", "2. What?! No.", "3. [Luck] Let me in for free?"]
    option2_1 = ["Okay. Here you go you cheeky guard.", "What?! No.", "3.Let me in for free?"]
    for o2 in option2:
    print(o2)
    answer2 = input("> ")
    if answer2 == "1":
        print(option2_1[0])
        print("Lost 500 Chromosomes")
        print("Guard: You can go ahead now.")
        chromosomes = (chromosomes) - 500
    elif answer2 == "2":
        print(option2_1[1])
        print("Guard: Get out of here then you piece of crap.")
        sys.exit()
    elif answer2 == "3":
        for rng in range(1):
            rng = random.randint(1, 101)
            print(rng)
            if rng <= 50:
                print("Guard: You wish. Get out of here then you piece of crap. ")
            elif rng >= 50:
                print("Guard: *sigh* Okay. Come inside already")

Tags: ofinyougoforhereprintelif
1条回答
网友
1楼 · 发布于 2024-06-11 16:38:59

似乎您已经使用同一变量两次了。你知道吗

你的循环:

对于范围(1)内的rng:

使用与随机化器变量相同的变量。你知道吗

rng=随机.randint(1,101)

切换一个变量名,它应该可以正常工作!你知道吗

另外,使用较短的范围来最小化错误,1-2而不是1-101

希望这有帮助!你知道吗

相关问题 更多 >