0
我試圖讓我的輸入是這樣的,但我不知道我應該怎麼格式化:Python的輸入格式
Enter the rainfall for January: 1
Enter the rainfall for February: 2
Enter the rainfall for March: 3
這是inputt我得到:
Enter the rainfall for January: 1
Enter the rainfall for February: 2
Enter the rainfall for March: 3
這裏我的代碼:
def main():
months=("January","February","March","April","May","June","July","August","September","October","November","December")
values=[0]*12
for n in range(len(values)):
print("Enter the rainfall for", (months[n]), end=": ")
values[n]=float(input())
main()
只是要清楚這裏節省一些打字,它的工作,因爲我們知道所有月份的長度。在一般情況下,我們將找到字符串的最大長度,然後使用s.ljust(max_len)之類的東西來執行填充。 – user3820547 2014-12-13 19:28:33