Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYTHON : Simple random generation driving if/else

new to programmation, im learning and here is probably a very simple problem for you guy.

import random

def run_stair_yes():
    print "\nRunning in stairs is very dangerous!"
    print "Statistique shows that you have 70% chance of falling"
    print "\nroll the dice!"


    for i in xrange(1):
        print random.randint(1, 100)

    if i <= 70 :
        print "\nWell, gravity is a bitch. You fell and die."

    elif i >= 71 :
        athlethic()

    else: 
            print "im boned!"
            exit(0)

my problem is that, whatever number is generated, it's always giving me the same "gravity is a bitch. You fell and die".

where do i go wrong ?

like image 688
inick Avatar asked Dec 17 '22 01:12

inick


1 Answers

You never actually set i to the random.randint()

You say

for i in xrange(1):

Where i takes the value of 0 as you iterate through the xrange(1) and then you just print out the result of random.randint(1, 100), not assigning it to i.

Try this

i = random.randint(1, 100)
like image 168
jamylak Avatar answered Dec 28 '22 05:12

jamylak