2017-10-14 176 views
0

當我嘗試運行它時,我在程序結束時獲取了EOF。我真的不知道如何解決它。起初我得到了「如果」作爲一個無效的語法,但我認爲我能夠解決這個問題。感謝您的幫助如何解決在python 3.6解析時意外的EOF?

而真:

try: 

    print("Do you want to enter a number?") 
    print("y - yes") 
    print("n - no") 
    choice = int(input("Enter here: ")) 
    if choice == y: 
     print("") 
     count = number 

    for indice in range(1,number + 1, 1): 
     print(number + indice) 
     print("") 
     print("All done") 

回答

1

你缺少except匹配try

請注意,即使您添加了except,您的代碼還有其他問題會打破它。例如,

if choice == y: 
... 

這應該是'y'而不是y。實際上,y預計會是一個變量,但您希望匹配用戶輸入'y''n'

另外,如果你想有一個字符串輸入,則:如果輸入

choice = int(input("Enter here: ")) 

將拋出一個錯誤,比方說,'y'

invalid literal for int() with base 10: 'y' 

嘗試採取的東西在一次一行和確保你瞭解每個點應該發生的事情,並對其進行測試。然後把它們放在一起。

+0

這比我的老師可以給我更多的幫助,謝謝。 – Aaron

+0

不客氣。如果此答案解決了您的問題,請通過單擊答案左側的複選框將其標記爲已接受。 –

相關問題