【发布时间】:2022-11-17 22:55:43
【问题描述】:
我遇到了这个错误语法错误,我无法在不破坏它的情况下找出任何其他解决方案
#function for calculating revenue
def revenue(x):
return 0.05x+2.5
#function for calculating cost
def cost(x):
return 0.03x
#opening the txt file in read mode which contains the sales data
sales = open("data.txt", "r") ;
total_revenue=0;
total_cost=0;
#reading the sales data line by line
for x in sales:
#calculating total revenue
total_revenue+=revenue(int(x))
#calculating total cost
total_cost+=cost(int(x))
#calculating profit
profit=total_revenue-total_cost
#printing the profit
print(profit)
#closing the sales file
sales.close()
输出应该是:-
(基础)aky03@Ajits-MacBook-Air 100ct % python main.py
40.7 但它不工作
【问题讨论】:
-
0.5x之类的东西不是编写产品的有效方式。使用0.5*x。您在整个代码中系统地执行此操作。 -
编程不是数学。您不能编写
0.5x并期望它执行乘法:您必须实际使用乘法运算符0.5 * x。
标签: python