2014-10-01 30 views
0

高清的main():如何每月打印號碼?

x = eval(input("Enter the number of the month you wish to know how much you have: ")) 
for month in (1, 2, 3, 4): 
    print("for this month 1 you have" , month * 10 , "dollar") 

的main()

我想要得到這樣的結果,一旦運行:

請輸入天數:4 月1:$ 10 第2個月:$ 20 3個月:$ 30 4個月:我有問題編號一個月的每一行:($ 40

回答

0

使你的代碼改爲:

print("for this month {month} you have".format(month=month) , month * 10 , "dollar") 

真正神奇的是Python的.format()。您可以在Python Documentation中閱讀更多關於它的信息。

您也可以只有:"for this month {} you have".format(month)

+0

謝謝! (花了3個小時卡在那裏) – mac 2014-10-01 22:36:26

+0

很高興我可以幫助你!如果我正確回答了您的問題,請將我的回答標記爲已接受。 – 2014-10-01 22:54:05