-2
我寫了一個多選題程序,它不像我期望的那樣行事。Python - if else - 程序流程
我希望它這樣的行爲 - 當您鍵入1,去下面#USD塊和
- 當你鍵入2,它應該去塊下面#Euro
這裏是我的代碼:
print "Welcome to Currency Converter By Fend Artz"
print "your options are:"
print " "
print "1) GDP -> USD"
print "2) GDP -> Euro"
USD = int(raw_input(''))
if USD == 1:
choice = USDchoice
elif USD == 2:
choice = EUROchoice
else:
print ("You have to put a number 1 or 2")
int(raw_input(''))
#USD
def USDchoice():
userUSD = float(input('How many pounds do you want to convert?(e.g. 5)\n'))
USD = userUSD * 0.65
print userUSD, "Pounds =",USD,"USDs"
#Euro
def EUROchoice():
userEURO = float(input('How many pounds do you want to convert?(e.g. 5)\n'))
Euro = userEURO * 1.37
print userEURO, "Pounds =",Euro,"Euros"
#Thing so the script doesn't instantly close
Enter = raw_input('press ENTER to close\n')
選擇= USDchoice() – Alexander
要設置'choice'的功能,但你不叫它。 – cmd
添加()使其調用該函數。 –