dimanche 25 octobre 2015

Unable to renew random number on python

I'm new to python programming and I'm trying to do a simple command line game. Basically the command line asks for a number from 1 to 3, the user gives the number, the command line then compares it to a random number and decides if the winner passes or not, if he passes the hole thing repeats until he misses the number. My problem is renewing the random number for the next fase! I need a new random number for each time the command line compares it to the user's number.

Here's my code:

#!/usr/bin/env python

#ChooseADoor

from random import randint
import time
import sys
print("Welcome mortal, to the Choose a door game...")
Score = 0
StrScore = str(Score)

#DeathDoor = 0
#DeathDoor = randint(1,3)



tutorialRequired = input("Would you like to go through the tutorial? (YES / NO): ")

if tutorialRequired == "YES":
    print("""Alright mortal, you were kidnaped and you wake up in a room.
There are 3 doors, two of them let you continue,
one of them gives you a painful death...
Yeah, sorry about that...
    """)
    ready = input("Ready mortal? (YES / NO): ")
    if ready =="YES":
        print("Starting game in 3...")
        time.sleep(1)
        print("2...")
        time.sleep(1)
        print("1...")
        time.sleep(1)
        print("GO!")
        time.sleep(1)
    else:
        print("Goodbye mortal.")
        sys.exit()
else:
    print("""Alright smarty pants let's see if you live to tell your story...
    """)
    ready = input("Ready mortal? (YES / NO): ")
    if ready =="YES":
        print("Starting game in 3...")
        time.sleep(1)
        print("2...")
        time.sleep(1)
        print("1...")
        time.sleep(1)
        print("GO!")
        time.sleep(1)
    else:
        print("Goodbye mortal.")
        sys.exit()


while Score < 10:

    print("Three doors ahed... ")
    door = input("Pick one (1, 2, 3): ")
    doorNum = int(door)


    if door in ("123"):
        DeathDoor = 0
        DeathDoor = randint(1,3)

        if DeathDoor == door:

            print("End of line, mortal.")
            print("You passed", StrScore, ("doors until the endo of your miserable life..."))

            break
        else:
            RandomNum = 0
            RandomNum = randint(1,3)
            if RandomNum == 1:
                print("You're safe for now, mortal. Go on.")
                DeathDoor = 0
                Score = (Score + 1)
                StrScore = str(Score)
                print("Score: " + StrScore)
            elif RandomNum == 2:
                print(" Beginner's luck. Let's see if you laugh next time mortal.")
                DeathDoor = 0
                Score = (Score + 1)
                StrScore = str(Score)
                print("Score: " + StrScore)
            elif RandomNum == 3:
                print(" Keep the fireworks, they may be useful for your funeral. Go on.")
                DeathDoor = 0
                Score = (Score + 1)
                StrScore = str(Score)
                print("Score:" + StrScore)

    else:
        print("Don't try to fool me,")
        print("goodbye mortal.")
        StrScore = str(Score)
        print("You passed " + StrScore + (" doors until the endo of your miserable life..."))
        time.sleep(1)
        sys.exit()

StrScore = str(Score)
print("Congratulations mortal, you live. For now."))

What am I doing wrong?

Thank you for your time!




Aucun commentaire:

Enregistrer un commentaire