0

This is a basic loot table for a python game.

  1. Common if the drop rolls on any number till and including 13
  2. Uncommon if the drop rolls 14 through to, and on 18
  3. Rare if the drop rolls on 19 or 20

The program ignores the rare drop table even when the conditions are met and instead takes an item from the uncommon drop table e.g drop = 20 1000 gold coins

Can someone explain the problem here?

import random


player_won = True

def common():
    common_drop= ['Dragon Bones','Dragon Hide','Dragon Teath','Steel Scimitar','Iron Arrows','Bronze Kitesheild']
    print(random.choice(common_drop))
    

def uncommon():
    uncommon_drop= ['Rune Platebody','1000 Gold Coins','Dragonstone','Rune longsword','Mithril Javelin','Rune Med Helm']
    print(random.choice(uncommon_drop))
    
    
def rare():
    rare_drop= ['Dragon Head','Gold Trimmed Rune Full Helm','Crystal Halberd','Diamond (uncut)']
    print(random.choice(rare_drop))    

while player_won == True:
    drop = random.randint(1,20)
    print(drop)
    if drop <= 13:
        common() 
    elif drop > 13 <= 18:
        uncommon()
    elif drop == 19 or 20:
        rare()
    break        
A P
  • 19
  • 1
  • Also https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true – mkrieger1 Oct 11 '20 at 20:39
  • This is because of your second `elif` condition - 13 is always less than or equal to 18. – n1c9 Oct 11 '20 at 20:40
  • Also [How to test multiple variables against a value?](https://stackoverflow.com/q/15112125/4518341) – wjandrea Oct 11 '20 at 20:40
  • 2
    tl;dr `13 < drop <= 18` and `drop in {19, 20}` – wjandrea Oct 11 '20 at 20:41
  • `drop > 13 <= 18` is `True <= 18` (since if `drop <= 13` were true, we wouldn't be in the `elif` part) a.k.a. `1 <= 18`, therefore `uncommon()` is always executed (unless `drop <= 13`) and `rare()` is never executed. – mkrieger1 Oct 11 '20 at 20:44

1 Answers1

1

You need to move your drop variable in the uncommon elif; so it looks like

elif 13 < drop <= 18:
Ponyboy
  • 76
  • 5