我对Python很陌生(2天),我很难找到一个解决方案,将变量添加到具有定义值的字典以及
choice = input("")
if choice == "1":
print ("1.Basic - £8")
print ("2.Standard- £13")
print ("3.Premium- £25")
Premium = dict(name ="Premium",
Cost = 25.0)
Standard = dict(name ="Standard",
Cost = 13.0)
Basic = dict(name ="Basic",
Cost = 8.0)
Grass_Dict = {}
Premium = input("Type Premium")
Basic = print(input("Type '3' for Basic")
Grass_Dict['1'] = Premium
Grass_Dict['2'] = Standard
Grass_Dict['3'] = Basic
然后我尝试将变量添加到代码的第二部分,这样当我引用成本计算时,我将能够使用存储的变量并使用它的值(25.0)。 / p>
elif(选择==" 2"):
time.sleep(0.2)
print("-")
time.sleep(0.2)
print("-")
print("2.Select Area of Grass")
print("1.Select Shape Required")
if (choice =="1"):
print("Grass Calculation Program")
print("Select Shape Required")
print("1.Square")
print("2.Triangle")
print("3.Circle")
shape = input ("Please Select (1/2/3)")
if choice =="1":
length = input ("Please Enter Length")
width = input ("Please Enter Width")
area = (length*width)
print ("Calculating Cost")
elif choice =="2":
length = input ("Please Enter Length")
width = input ("Please Enter Width")
感谢大家的帮助!