无法弄清楚如何获得某事发生的百分比机会

问题描述 投票:0回答:1

我正在制作一个基于文本的游戏;我试图找出一种方法来为每种情况发生多个结局和某些百分比,但是当我运行它时,它会产生奇怪的字母,有时会出现多个结尾。

choice1_wakeup = input ("Wake Up? Y or N:")
if choice1_wakeup == 'y' or choice1_wakeup == 'Y':
    print ("Placeholder")
else:
    import random
    for x in range(100):
        ending_percent = (random.randint(1,10)) 
        if ending_percent > 2:
            choice1_ending_common = ("You are woken a while later and see the priest holding a knife to your throat for a moment before he slits it and you bleed out.")
            print (random.choice(choice1_ending_common))
        elif ending_percent < 2 and ending_percent >0.5:
            choice1_ending_rare = ("You wake up a little while later and find yourself dangling over the mouth of the sacrificial volcano while your tribe chants the name of the fire goddess, kahuahuahua, kahuahuahua, kahuahuahua. “What’s happening?” you ask the priest. “You are being sacrificed for your crimes” he replies and at that he tosses you into the fiery abyss.","A few minutes later you are woken by  the suddenly extremely cold temperatures. You look around and spot the god of death daharasus. “Why haven’t you completed your rituals to me yet?” he asks you in a stone cold voice. “I’m sorry, I fell asleep” you frightendly reply. “I don’t want excuses!” he screams, he levels his finger at you and you are instantly killed, your soul is forever trapped in the same spot reliving that moment over and over forever.")
            print (random.choice(choice1_ending_rare))
        else:
            choice1_ending_impossible = input ('You are woken up by a stranger a few hours later. "Who are you?" you ask the strange man standing over you. "My name is Jeff Probst" he replies. "I was wondering if you would like to be on my new TV show?" Y or N:')
            if choice1_ending_impossible >= 'y' or choice1_ending_impossible >= 'Y':
                print ("impossible test")
python
1个回答
0
投票

请阅读choice方法的文档。该方法从您给出的可迭代序列中选择一个随机元素。在这种情况下,您提供的序列是单个结尾的文本。可用的选择是结尾的单个字母,所以......你得到一个随机的字符。

如果要选择随机文本,则需要为其提供字符串列表,例如

ending_list = [
    ["You and your team vote Jeff Probst off the island.",
     "You eat five ugly things and win the immunity challenge.",
     "The show is canceled for lack of geologically stable shooting locations."]

现在你可以从ending_list中选择一个元素。这足以让你去吗?

© www.soinside.com 2019 - 2024. All rights reserved.