python - 如何让程序询问用户输入的数量,并将他们输入的结果加在一起?
问题描述
我目前正在尝试制作一个程序,根据您之前获得的成绩以及它们对您的学期成绩有多大影响来计算您的最终学期成绩。问题是我正在努力弄清楚如何让程序询问用户他们收到的成绩数量,然后要求相同数量的成绩。
简而言之,该程序应该执行以下操作:
询问收到的成绩数量
询问用户获得的分数以及该分数的百分比 x 次,其中 x 是用户在第一个问题上给出的数字。
根据输入计算最终学期成绩。
我希望有人能提供帮助,到目前为止,我已经制作了这段代码,以防它帮助你理解我想要做什么。
grade1 = int(input("What was the first grade you received? " ))
percentage1 = float(input("What's the percentage of the first grade? "))
grade_value1 = grade1 * percentage1
grade2 = int(input("\nWhat was the second grade you received? "))
percentage2 = float(input("What's the percentage of the second grade? "))
grade_value2 = grade2 * percentage2
grade3 = int(input("\nWhat was the third grade you received? " ))
percentage3 = float(input("What's the percentage of the third grade? "))
grade_value3 = grade3 * percentage3
finale_grade = grade_value1 + grade_value2 + grade_value3
if finale_grade < 2.9:
print("\nYour finale grade is 2")
elif finale_grade < 5.4:
print("\nYour finale grade is 4")
elif finale_grade < 8.4:
print("\nYour finale grade is 7")
elif finale_grade < 10.9:
print("\nYour finale grade is 10")
else:
print("\nYour finale grade is 12")
解决方案
#I hope this works , I'm a beginner tho
num_of_recieved_grades = int(input("number of recieved
grades ?"))
final_grade = 0
# for loop in range of the number entered
for x in range (num_of_recieved_grades ):
grade = int(input("what is the grade"))
percentage = float(input("what is the percentage"))
final_grade += grade * percentage
推荐阅读
- django - DetailView重定向在django中不起作用
- c++ - 当 NUL 字符被定义为字符串的一部分时,为什么 strlen() 不计算终止 NUL 字符的字节?
- javascript - 自动javascript控制台
- user-interface - 如何使用父“模型”访问子“模型”数据以在 extjs 的网格中显示
- java - JOptionPane 对话框在 Eclipse 中未正确显示
- makefile - 为什么 CMake 会删除我的 add_custom_command 源文件
- mysql - 如何使用 NodeJS 更新数据?
- ruby - URI 只能是 ascii
- javascript - 页面刷新后如何停止计时器重置
- reactjs - 我的 onchange 方法在反应中不起作用