无法弄清楚如何获得某些事情的百分比收入

时间:2018-03-05 19:01:10

标签: python

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

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")

1 个答案:

答案 0 :(得分:0)

请阅读select d.key from data d group by d.key having max(case when d2.code = 2 then date end) > max(case when d2.code <> 2 then date end); 方法的文档。该方法从您给出的可迭代序列中选择一个随机元素。在这种情况下,您提供的序列是单个结尾的文本。可用的选择是结尾的单个字母,所以......你得到一个随机的字符。

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

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."] 中选择一个元素。这足以让你前进吗?