Python3:运算符-缩进错误
此代码在第行生成一个缩进错误Python3:运算符-缩进错误,python,Python,此代码在第行生成一个缩进错误 if __name__ == '__main__' 如果有人能解释编译代码的原因和解决方案,我将不胜感激 #/垃圾桶/蟒蛇3 输入数学 导入操作系统 随机输入 进口稀土 导入系统 #完成下面的求解函数。 def解决方案(餐费、小费百分比、税金百分比): 如果uuuu name uuuuu=='\uuuuuuu main\uuuuuu' 膳食成本=浮动(输入()) 提示百分比=int(输入()) 税收百分比=int(输入()) 解决(餐费、小费、税金) 小费=餐费*
if __name__ == '__main__'
如果有人能解释编译代码的原因和解决方案,我将不胜感激
#/垃圾桶/蟒蛇3
输入数学
导入操作系统
随机输入
进口稀土
导入系统
#完成下面的求解函数。
def解决方案(餐费、小费百分比、税金百分比):
如果uuuu name uuuuu=='\uuuuuuu main\uuuuuu'
膳食成本=浮动(输入())
提示百分比=int(输入())
税收百分比=int(输入())
解决(餐费、小费、税金)
小费=餐费*小费百分比
税=餐费*税百分比
总计=餐费+小费+税金
您错过了将行缩进四个空格,还忘记了:
冒号,还更改了顺序,请尝试将函数更改为:
def solve(meal_cost, tip_percent, tax_percent):
meal_cost = float(input())
tip_percent = int(input())
tax_percent = int(input())
solve(meal_cost, tip_percent, tax_percent)
if __name__ == '__main__':
tip = meal_cost * tip_percent
tax = meal_cost * tax_percent
total = meal_cost + tip + tax
看起来此函数与其主体的分离不正确:
# Complete the solve function below.
def solve(meal_cost, tip_percent, tax_percent):
tip = meal_cost * tip_percent
tax = meal_cost * tax_percent
total = meal_cost + tip + tax
if __name__ == '__main__':
meal_cost = float(input())
tip_percent = int(input())
tax_percent = int(input())
solve(meal_cost, tip_percent, tax_percent)
您忘记了第
行中的缩进if uuu name uu=='.\uu main uu'
并且在同一行中也缺少了:
,只需在if uu name u='.\uu main
之后加上:就可以了