我的代码在=部分的“<;=80”行返回错误。为什么?我该怎么修?你知道吗
#Procedure to find number of books required
def number_books():
number_books = int(raw_input("Enter number of books you want to order: "))
price = float(15.99)
running_total = number_books * price
return number_books,price
#Procedure to work out discount
def discount(number_books):
if number_books >= 51 and <= 80:
discount = running_total / 100 * 10
elif number_books >= 11 and <=50:
discount = running_total / 100 * 7.5
elif number_books >= 6 and <=10:
discount = running_total / 100 * 5
elif number_books >=1 and <=5:
discount = running_total / 100 * 1
else print "Max number of books available to order is 80. Please re enter number: "
return discount
#Calculating final price
def calculation(running_total,discount):
final_price = running_total - discount
#Display results
def display(final_price)
print "Your order of", number_books, "copies of Computing science for beginners will cost £", final_price
#Main program
number_books()
discount(number_books)
calculation(running_total,discount)
display(final_price)
任何帮助都将不胜感激
这是无效的:
尝试:
所有其他事件也是如此
或者,正如尼诺所说
此外,您需要在最后以正确的方式返回折扣(这将是解决此问题后您将遇到的另一个问题)。你知道吗
所以
如果要进行范围测试,可以使用chained comparison:
至于为什么会出现语法错误:
and
(或or
)运算符的两边都必须是完整表达式。因为<= 80
不是一个完整的表达式,所以会出现语法错误。您需要编写number_books >= 51 and number_books <= 80
来修复这个语法错误。你知道吗相关问题 更多 >
编程相关推荐