Python 知道语法错误是什么吗?
显然总数是个错误?我想知道为什么它会这样说,因为它以前没有这样说。可能是我糟糕的编码 这一行是错误的:Python 知道语法错误是什么吗?,python,Python,显然总数是个错误?我想知道为什么它会这样说,因为它以前没有这样说。可能是我糟糕的编码 这一行是错误的: car = input("Audi TT + Licence + Tax: 4000") car = int(car) insurance = int(input("Insurance: 1500 ")) petrol= int(input("Petrol Per Month: 250*12 ")) dealerprep= int(input(input("Dealer Prep: 2000:
car = input("Audi TT + Licence + Tax: 4000")
car = int(car)
insurance = int(input("Insurance: 1500 "))
petrol= int(input("Petrol Per Month: 250*12 "))
dealerprep= int(input(input("Dealer Prep: 2000: "))
total = car + insurance + petrol + dealerprep
print("\nGrand Total :", total)
input("\n\nPress the enter key to exit.")
应该是
dealerprep= int(input(input("Dealer Prep: 2000: "))
只需等待,直到您运行程序-然后输入输入
dealerprep= int(input("Dealer Prep: 2000: "))
然后跑,
#example.py
car = input("Audi TT + Licence + Tax: ")
car = int(car)
insurance = int(input("Insurance: "))
petrol= int(input("Petrol Per Month: "))
dealerprep= int(input("Dealer Prep: "))
total = car + insurance + petrol + dealerprep
print("\nGrand Total :", total)
input("\n\nPress the enter key to exit.")
按enter键退出#我按下回车键,程序停止运行
一个音符。如果要输入表达式(如45*20),则应将该表达式传递给eval()funxtion
在您的情况下,如果您想输入“每月汽油”,如45*20
,请尝试
$ python3 example.py
Audi TT + Licence + Tax: 34
Insurance: 453
Petrol Per Month: 645
Dealer Prep: 64557
Grand Total : 65689
否则将引发ValueError
petrol= eval(input("Petrol Per Month: "))
>c=int(输入(“每月汽油:”)
每月汽油:45*20
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ValueError:基数为10的int()的文本无效:“45*20”
您是否试图通过提示将值传递给输入
?此外,input(input(…)
没有多大意义。input(input(“我应该问你什么问题?”)
:p@ForceBru哇,冷静点,我才刚开始编程,所以我肯定会出错的!你最近的错误是什么?请复制粘贴错误。字面上只是说语法错误,就这样?
>>> c = int(input("Petrol per Month: "))
Petrol per Month: 45*20
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '45*20'