将项目存储在字典中,然后用于计算

2024-04-20 01:27:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我对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)

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")

谢谢大家的帮助


Tags: nameinputifbasicselectdictstandardprint