簡體   English   中英

為什么我在Python中不斷收到任意語法錯誤?

[英]Why do I keep getting arbitrary syntax errors in Python?

我正在用python寫一個簡單的腳本來返回GDP值。 從第6行開始,它給出了“語法錯誤”,無需進一步說明。 我注釋掉了所有與該問題有關的行(第6行到第6行),在第16行,我收到了“解析時出現EOF”錯誤。 我真的不確定該怎么做,因為我檢查了不匹配的定界符,不正確的語法等,但是我唯一能找到的是我執行打印語句的方式,但是由於它們都是相同的,並且只有一個分析錯誤,這種情況不太可能發生。 這是代碼:

y_i = int(input("What year did your alt history begin?"))
y_f = 2014
p_i = int(input("Enter population of your territory starting from your alt history.")
p_g = int(input("Enter average population growth from year to year in a numerical value. No percentages.")
p_f = (p_i(p_g - y_f) ** 2)/(10000 * y_i ** 2)

print("This is your nation's population.", p_f, "If you got an error, check that you put in all inputs correctly.")

gdp_capita = int(input("What is your GDP per capita? Please use the number only, in your own currency.")


gdp = pop * gdp_capita

print("This is your nation's GDP.", gdp, "If you get an error, please check that you entered everything in correctly.")

你的錯誤在你的syntaxing。 您缺少右括號。 在第3、4和9行上,您需要: int(input("...")沒有最后一個括號!您還試圖在第5行中調用p_f = p_i(p_g...)的整數) p_f = p_i(p_g...) 。我以為您正在嘗試進行乘法運算,因此我在此處加了一個乘號(一個星號)。另外,請確保您現在確保雙星號的意思是“至...的冪” 2**3 = 8 ,而不是6

將代碼更改為此:

y_i = int(input("What year did your alt history begin?"))
y_f = 2014
p_i = int(input("Enter population of your territory starting from your alt history."))
p_g = int(input("Enter average population growth from year to year in a numerical value. No percentages."))
p_f = (p_i*(p_g - y_f) ** 2)/(10000 * y_i ** 2)

print("This is your nation's population.", p_f, "If you got an error, check that you put in all inputs correctly.")

gdp_capita = int(input("What is your GDP per capita? Please use the number only, in your own currency."))


gdp = pop * gdp_capita

print("This is your nation's GDP.", gdp, "If you get an error, please check that you entered everything in correctly.")

但是你在第1行就對了:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM