简体   繁体   中英

RNG for my text-based game in python3

I am new to programming and to test myself, I tried making a text-based game. The problem is, in the selection of dialogue, I included a speech check where it will be based on RNG but I just can't get it right. I am sorry if this is a dumb question but I am really lost.

Here is the part of the code:

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

It seems that you have used the same variable twice.

Your loop:

for rng in range(1):

uses the same variable as the randomizer variable.

rng = random.randint(1, 101)

Switch a variable name and it should work fine!

Also, use a shorter range to minimize errors, 1-2 rather than 1-101

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM