mardi 2 juillet 2019

Why does my code keep going with else statement?

So I am trying to make a dice roller app for my friends and I for a pen and paper RPG we play. The number on the die correlates to a certain outcome, so I made a dictionary to record those outcomes and an if statement to call those outcomes out. The problem is, my program doesn't recognize the value of the die being cast for certain numbers and only outputs the 'else' statement.

I have tried using ranges, greater than and less than statements (tying in the 'and' logic statement), and have come to a simple range statement. My code says that nothing is wrong, it just outputs the 'else' statement for numbers 3-9.

sroll=dict()
sroll[1]="Blank"
sroll[3]="Opp"
sroll[6]="Succ/Str"
sroll[8]="Succ"
sroll[10]="Succ/Opp"
sroll[11]="Crit/Str"
sroll[12]="Crit"



numsdie=int(input("Now how many skill die would you like to cast?"))

def sroller():
    if diecasts<=2:
        print(sroll[1])
    elif 3 < diecasts < 5:
        print(sroll[3])
    elif 6 < diecasts < 7:
        print(sroll[6])
    elif 8 < diecasts < 9:
        print(sroll[8])
    elif diecasts==10:
        print(sroll[10])
    elif diecasts==11:
        print(sroll[11])
    else:
        print(sroll[12])

for _ in range (numsdie):
    diecasts=int(randint(1,12))
    print(diecasts)
    sroller()

No error messages pop up, but if the randint gave me a number below 2, the expected answer would be outputted. But when any number between 3,9 was given by the randint, the program would output "Crit", which should only be the case if the randint outputted a 12. When the randint outputs 1,2,10,11,12. They give the correct statements back. Any help would be appreciated on either condensing the code or solving the issue.

Aucun commentaire:

Enregistrer un commentaire