Python循环结构全解析
1. 重复结构简介
在编程中,我们常常需要多次执行相同的任务。例如,要为多个销售人员计算10%的销售佣金。一种方法是为每个销售人员编写一次计算佣金的代码,如下所示:
# Get a salesperson's sales and commission rate.
sales = float(input('Enter the amount of sales: '))
comm_rate = float(input('Enter the commission rate: '))
# Calculate the commission.
commission = sales * comm_rate
# Display the commission.
print('The commission is $', format(commission, ',.2f'), sep='')
# Get another salesperson's sales and commission rate.
sales = float(input('Enter the amount of sales: '))
comm_rate = float(input('Enter the commission rate: '))
# Calculate the commission.
commission = sales * comm_rate
# Display the commission.
print('The commission is $', format(commission, ',.2f'), sep='')
超级会员免费看
订阅专栏 解锁全文
1615

被折叠的 条评论
为什么被折叠?



