Nov-13-2019, 06:09 PM
So yeah, I'm trying to make a simple randomized generator in Python for my own-design board game but I found a problem. To be more specific, I want to generate a list of items that the player will gain by a specific rule (i don't want to go deeper into the rules
). Now the problem is, that sometimes (depending on what generates), Python screams at my face that:
Code:
). Now the problem is, that sometimes (depending on what generates), Python screams at my face that:Error:Traceback (most recent call last):
File "main.py", line 358, in <module>
print(count, end=' ')
NameError: name 'count' is not definedNow, when you'll browse the code i'm putting below, you'll notice that the variable 'count' IS defined. It's probably a "missclick" of mine or sth like that but I have no idea where and how does it look. Can you help me?Code:
import random
#type of tool
tool = input("Please enter the type of tool you want to use (A=axe,S=shovel,H=hoe or shears,P=pickaxe,B=bucket): ")
#tool material
if (tool == "A") or (tool == "S") or (tool == "P"):
material = int(input("Please enter the numerical ID of the tool's material (0=no tool(hand),1=wood,2=stone,3=iron,4=diamond,5=gold): "))
elif tool == "H":
material = int(input("Please enter the numerical ID of the tool's material (0=no tool(hand),1=wood,2=stone,3=iron,4=diamond,5=gold,6=shears): "))
#silk touch
if (tool != "B") and (material != 0):
st = input("Is your tool enchanted with Silk Touch?(Y/N)")
#fortune
if (tool == "S" or (tool == "H" and material != 6) or tool == "P") and (material != 0):
ft = int(input("Please enter the level of Fortune enchantment on your tool: "))
print("", end='\n')
print("You've collected:", end='\n')
#axe
if tool == "A":
if material == 0:
r = 1
while r > 0:
count = 1
item = "oak log"
print(count, end=' ')
print(item)
r = r - 1
elif material == 5:
r = 1
while r > 0:
x = random.randint(1,100)
if x in range(1,50):
count = 1
item = "oak log"
elif x in range(51,100):
count = 1
item = "pumpkin"
print(count, end=' ')
print(item)
r = r - 1
else:
r = material
while r > 0:
x = random.randint(1,100)
if x in range(1,90):
count = 1
item = "oak log"
elif x in range(91,100):
count = 1
item = "pumpkin"
print(count, end=' ')
print(item)
r = r - 1
#shovel
elif tool == "S":
if material == 0:
r = 1
while r > 0:
count = ""
item = "nothing"
print(count, end=' ')
print(item)
r = r - 1
elif material == 5:
r = 1
while r > 0:
x = random.randint(1,3)
if x == 1:
count = 1
if st == "N":
item = "dirt"
elif st == "Y":
item = "grass block"
elif x == 2:
count = 1
item = "dirt"
else:
if st == "N":
count = 4
item = "clay"
elif st == "Y":
count = 1
item = "clay block"
print(count, end=' ')
print(item)
r = r - 1
else:
r = material
while r > 0:
x = random.randint(1,100)
if x in range(1,20):
count = 1
if st == "N":
item = "dirt"
elif st == "Y":
item = "grass block"
elif x in range(21,80):
count = 1
item = "dirt"
elif x in range(81,100):
if st == "N":
count = 4
item = "clay"
elif st == "Y":
count = 1
item = "clay block"
print(count, end=' ')
print(item)
r = r - 1
#hoe
elif tool == "H":
if material == 0:
r = 1
while r > 0:
count = ""
item = "nothing"
print(count, end=' ')
print(item)
r = r - 1
elif material == 5:
r = 1
while r > 0:
x = random.randint(1,11)
if x == 1:
if st == "N":
sapling = random.randint(1,10000)
stick = random.randint(1,10000)
apple = random.randint(1,100000)
if (ft == 0) or (ft > 3):
if sapling in range(1,500):
count = 1
item = "oak sapling"
elif stick in range(1,200):
count = 1
item = "stick"
elif ft == 1:
if sapling in range(1,625):
count = 1
item = "oak sapling"
elif stick in range(1,222):
count = 1
item = "stick"
elif ft == 2:
if sapling in range(1,833):
count = 1
item = "oak sapling"
elif stick in range(1,250):
count = 1
item = "stick"
else:
if sapling in range(1,1000):
count = 1
item = "oak sapling"
elif stick in range(1,333):
count = 1
item = "stick"
elif st == "Y":
count = 1
item = "oak leaves"
elif x == 2:
if st == "N":
if (ft == 0) or (ft > 3):
seeds = random.randint(0,1)
if seeds == 0:
count = ""
item = "nothing"
else:
count = 1
item = "wheat seeds"
else:
seeds = random.randint(0,1+ft)
if seeds == 0:
count = ""
item = "nothing"
else:
count = random.randint(1,1+(2*ft))
item = "wheat seeds"
elif st == "Y":
count = 1
item = "grass"
elif x == 3:
count = 1
item = "dandelion"
elif x == 4:
count = 1
item = "poppy"
elif x == 5:
count = 1
item = "azure bluet"
elif x == 6:
count = 1
item = "red tulip"
elif x == 7:
count = 1
item = "orange tulip"
elif x == 8:
count = 1
item = "white tulip"
elif x == 9:
count = 1
item = "pink tulip"
elif x == 10:
count = 1
item = "oxeye daisy"
else:
count = 1
item = "cornflower"
print(count, end=' ')
print(item)
if (ft == 0) or (ft > 3):
if apple in range(1,500):
print("1 apple")
elif ft == 1:
if apple in range(1,556):
print("1 apple")
elif ft == 2:
if apple in range(1,625):
print("1 apple")
else:
if apple in range(1,833):
print("1 apple")
r = r - 1
elif material == 6:
r = 1
while r > 0:
x = random.randint(1,100)
if x in range(1,60):
count = 1
item = "oak leaves"
elif x in range(61,91):
count = 1
item = "grass"
elif x == 92:
count = 1
item = "dandelion"
elif x == 93:
count = 1
item = "poppy"
elif x == 94:
count = 1
item = "azure bluet"
elif x == 95:
count = 1
item = "red tulip"
elif x == 96:
count = 1
item = "orange tulip"
elif x == 97:
count = 1
item = "white tulip"
elif x == 98:
count = 1
item = "pink tulip"
elif x == 99:
count = 1
item = "oxeye daisy"
else:
count = 1
item = "cornflower"
print(count, end=' ')
print(item)
r = r - 1
else:
r = material
while r > 0:
x = random.randint(1,100)
if x in range(1,60):
if st == "N":
sapling = random.randint(1,10000)
stick = random.randint(1,10000)
apple = random.randint(1,100000)
if (ft == 0) or (ft > 3):
if sapling in range(1,500):
count = 1
item = "oak sapling"
elif stick in range(1,200):
count = 1
item = "stick"
elif ft == 1:
if sapling in range(1,625):
count = 1
item = "oak sapling"
elif stick in range(1,222):
count = 1
item = "stick"
elif ft == 2:
if sapling in range(1,833):
count = 1
item = "oak sapling"
elif stick in range(1,250):
count = 1
item = "stick"
else:
if sapling in range(1,1000):
count = 1
item = "oak sapling"
elif stick in range(1,333):
count = 1
item = "stick"
elif st == "Y":
count = 1
item = "oak leaves"
elif x in range(61,91):
if st == "N":
if (ft == 0) or (ft > 3):
seeds = random.randint(0,1)
if seeds == 0:
count = ""
item = "nothing"
elif seeds == 1:
count = 1
item = "wheat seeds"
else:
seeds = random.randint(0,1+ft)
if seeds == 0:
count = ""
item = "nothing"
else:
count = random.randint(1,1+(2*ft))
item = "wheat seeds"
elif st == "Y":
count = 1
item = "grass"
elif x == 92:
count = 1
item = "dandelion"
elif x == 93:
count = 1
item = "poppy"
elif x == 94:
count = 1
item = "azure bluet"
elif x == 95:
count = 1
item = "red tulip"
elif x == 96:
count = 1
item = "orange tulip"
elif x == 97:
count = 1
item = "white tulip"
elif x == 98:
count = 1
item = "pink tulip"
elif x == 99:
count = 1
item = "oxeye daisy"
else:
count = 1
item = "cornflower"
print(count, end=' ')
print(item)
r = r - 1Reply
