Preparation
>>> import random
>>> combs =[]
>>> for x in["cheeseburger","Hamburger","Tomato burger"]:
for y in["potato","salad"]:
for z in["Shake","Cola","ダイエットCola"]:
combs.append((x,y,z))
#Preparation
>>> combs
[('cheeseburger', 'potato', 'Shake'), ('cheeseburger', 'potato', 'Cola'), ('cheeseburger', 'potato', 'ダイエットCola'), ('cheeseburger', 'salad', 'Shake'), ('cheeseburger', 'salad', 'Cola'), ('cheeseburger', 'salad', 'ダイエットCola'), ('Hamburger', 'potato', 'Shake'), ('Hamburger', 'potato', 'Cola'), ('Hamburger', 'potato', 'ダイエットCola'), ('Hamburger', 'salad', 'Shake'), ('Hamburger', 'salad', 'Cola'), ('Hamburger', 'salad', 'ダイエットCola'), ('Tomato burger', 'potato', 'Shake'), ('Tomato burger', 'potato', 'Cola'), ('Tomato burger', 'potato', 'ダイエットCola'), ('Tomato burger', 'salad', 'Shake'), ('Tomato burger', 'salad', 'Cola'), ('Tomato burger', 'salad', 'ダイエットCola')]
#Execution command
>>> combs[(random.randint(1,len(combs)+1))]
#Display example
>>> combs[(random.randint(1,len(combs)+1))]
('cheeseburger', 'salad', 'Diet cola')
>>> combs[(random.randint(1,len(combs)+1))]
('Hamburger', 'salad', 'Cola')
I can proceed to the above without delay.
>>> if x == "Hamburger":
X = 120
elif x == "cheeseburger":
X = 100
elif x=="Tomato burger":
X = 200
>>> if y == "salad":
Y = 150
elif y == "potato":
Y = 100
>>> if z == "Shake":
Z = 120
elif z =="Cola":
Z = 100
elif z =="Diet cola":
Z=150
As
>>>print(combs[(random.randint(1,len(combs)+1))],X+Y+Z)
Even if you type. The calculation part of X + Y + Z is the same value every time
('cheeseburger', 'potato', 'Cola') 500
('Tomato burger', 'potato', 'Shake') 500
So how can I get the calculation part to work every time?
Recommended Posts