python else语法错误_python3.5.1 if-else语句出现语法错误

博主在做作业时,代码中的if-else语句出现语法错误。代码涉及销售数据处理,在判断最高和最低销售额时出错,错误提示为Syntax Error。博主希望有人能帮忙找出错误来源。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我在做作业,看起来像这样:def main():

keep_going = 'y'

number_of_salespeople = 0

while keep_going == 'y' or keep_going == 'Y':

process_sales()

number_of_salespeople += 1

keep_going = input('Are there more salespeople? (enter y or Y for yes) ')

print(' ')

print('There were', number_of_salespeople, 'salespeople today.')

def process_sales():

print(' ')

name = input('What is the salesperson\'s name? ')

first_sale_amount = float(input('What is', name, '\'s first sale amount? '))

while 0 <= first_sale_amount <= 25000:

print('Error: that is not a valid sales amount. The amount must be greater than 0')

first_sale_amount = float(input('Please enter a correct sale amount: '))

highest_sale = first_sale_amount

lowest_sale = first_sale_amount

average_sale = first_sale_amount

number_of_sales = float(input('How many sales did', name, 'make this month? '))

for number in range(2, number_of_sales + 1):

sale_amount = float(input('Enter', name, '\'s time for sale #' + str(number) + ': '))

while 0 <= sale_amount <= 25000:

print('Error: that is not a valid sales amount. The amount must be greater than 0')

sale_amount = float(input('Please enter a correct sale amount: '))

if sale_amount > highest_sale:

highest_sale = sale_amount

else sale_amount < lowest_sale:

lowest_sale = sale_amount

total_sales += sale_amount

average_sale = (first_sale_amount + total_sales) / number_of_sales

print('The highest sale for', name, 'was', \

format(highest_sale, ',.2f'), \

sep='')

print('The lowest sale for', name, 'was', \

format(lowest_sale, ',.2f'), \

sep='')

print('The average sale for', name, 'was', \

format(average_sale, ',.2f'), \

sep='')

main()

我的错误在if-else语句的底部

^{pr2}$

错误如下:Syntax Error: else sale_amount < lowest_sale:: , line

58, pos 24

我看不出问题出在哪里,谁能帮我弄清楚错误是从哪里来的吗。谢谢你的帮助。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值