python输入学生成绩计算平均值_从用户输入中计算和、积和平均值

我正在做一些家庭作业,需要我做以下几点:Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing input. After the user presses the enter key, the program should print the sum of the numbers, the product of the numbers, and the average of the numbers.

Run your program with the following inputs:

1, 2, 3, 4, 5, 6, 7, 8

2, 24, 11, 1, 4, 10

Enter no number

这是我到目前为止的数据,但是我的数字没有正确地显示出来。谁能告诉我我做错了什么吗。我是个初学者,所以,如果你能用最简单的语言来表达,那就太好了。在

从用户处获取数字,直到用户按“回车”键

计算输入数字的总和、乘积和平均值

显示结果#main program start

def main():

#initialize variables

count = 0

sum = 0.0

product = 1.0

data = input("Enter a number or press Enter to quit: ")

while True:

#request input from user

data = input("Enter a number or press Enter to quit: ")

#set up the termination condition

if data == "":

break

#convert inputs into floats

number = float(data)

#calculate sum, product, and average

sum += number

product *= number

average = sum / number

#display results

print("The sum is", sum)

print("The product is", product)

print("The average is", average)

#main program end

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值