dimanche 19 mars 2017

How do i set a value to x if a random number is in-between 6 - 9

When I run my code, the numbers less than or equal to 6 show up as: x: 1. If the random number was 7, it wouldn't say x: 2. How do i fix it if the random number was in-between 6 - 9, it would print x: 2.

import random

for k in range(1,10):
    rnum =  random.randint(1, 10)
    print(rnum)
    if rnum <= 6:
        x = 1
        print("x:",x)

    elif rnum == (6,9):
        x = 2
        print("x:", x)

    elif rnum == 10:
        x = 3
        print("x:", x)

when you run code:

8
9
1
x: 1
1
x: 1
5
x: 1
1
x: 1
4
x: 1
9
4
x: 1

Process finished with exit code 0




Aucun commentaire:

Enregistrer un commentaire