我该如何为python修复这个货币转换器?

时间:2014-02-24 13:11:12

标签: debugging syntax

我已为货币转换器制作了此代码,但它提供了语法。请使用python 3.3.2。

currencynum = 0
yenpound=0.0059
yendoler=0.0098
yeneuro=0.0071
yenyen=1
yeneuro=0.0071
yenyen=1
poundyen=170.55
pounddoler=1.67
poundeuro=1.21
poundpound=1
dolpound=0.60
doleuro=0.73
doldol=1
dolyen=102.37
europound=0.83
eurodol=1.38
euroyen=140.79
euroeuro=1


tipe= input ("input what curontsy you have. yen y,us dollrus d, euro e, pound p.")
            if tipe == "y":
                print ("you have choson yen")

            elif tipe == "e":
                print("you have choson euro")

            elif tipe == "d":
                print ("you have choson us dollrus")

            elif tipe == "p":
                print ("you have choson pound")

            howmuch = float(input("how much do you have"))

            otheramount = input ("input what curontsy you want to convert. yen y,us dollrus, euro e, pound p.")

            if otheramount == "y":
                print ("you have choson yen")
            elif otheramount == "e":
                print("you have choson euro")

            elif otheramount == "us":
                print ("you have chosen us dollrus")

            elif otheramount == "p":
                print ("you have choson pound")


            if tipe == "y":


                   if otheramount == "y":
                       print ("yy")
                   currencynum=howmuch*yenyen
                   print (currencynum)

                   elif  otheramount == "e":
                       print ("ye")
                   currencynum=howmuch*yeneuro
                   print (currencynum)

                   elif otheramount == "d":
                       print ("yd")
                   currencynum=howmuch*pounddoler
                   print (currencynum)


                   elif otheramount == "p":
                       print ("yp")
                   currencynum=howmuch*yenpound
                   print (currencynum)


            elif tipe == "e":

                   if otheramount == "y":
                       print ("ey")
                   currencynum=howmuch*euroyen
                   print (currencynum)

                   elif otheramount == "e":
                       print ("ee")
                   currencynum=howmuch*euroeuro
                   print (currencynum)

                   elif otheramount == "d":
                       print ("ed")
                   currencynum=howmuch*eurodol
                   print (currencynum)

                   elif otheramount == "p":
                       print ("ep")
                   currencynum=howmuch*europound
                   print (currencynum)

            elif tipe == "d":

                   if otheramount == "y":
                       print ("dy")
                   currencynum=howmuch*dolyen
                   print (currencynum)

                   elif otheramount == "d":
                       print ("dd")
                   currencynum=howmuch*doldol
                   print (currencynum)

                   elif otheramount == "p":
                       print ("dp")
                   currencynum=howmuch*dolpound
                   print (currencynum)

                   elif otheramount == "e":
                       print ("de")
                   currencynum=howmuch*doleuro
                   print (currencynum)

            elif tipe == "p":

                   if otheramount == "y":
                       print ("py")
                   currencynum=howmuch*poundyen
                   print (currencynum)

                   elif otheramount == "p":
                       print ("pp")
                   currencynum=howmuch*poundpound
                   print (currencynum)

                   elif otheramount == "d":
                       print ("pd")
                   currencynum=howmuch*pounddoler
                   print (currencynum)

                   elif otheramount == "e":
                       print ("pe")
                   currencynum=howmuch*poundeuro
                   print (currencynum)


            #currency = tipe + otheramount

            #command=currency
            #total= howmuch *  currencynum
            #print (total)

1 个答案:

答案 0 :(得分:0)

你的问题似乎是来自糟糕的缩进.. 对于每个缩进,你需要大约4个空格(不知道这是否与版本相关,有时需要6或8?)然后它才能工作。 请记住,每个新的if语句都需要另一个缩进,并且你的乘法应该在if-block中,所以它也必须缩进!