首页 > 解决方案 > 如何让程序询问用户输入的数量,并将他们输入的结果加在一起?

问题描述

我目前正在尝试制作一个程序,根据您之前获得的成绩以及它们对您的学期成绩有多大影响来计算您的最终学期成绩。问题是我正在努力弄清楚如何让程序询问用户他们收到的成绩数量,然后要求相同数量的成绩。

简而言之,该程序应该执行以下操作:

  1. 询问收到的成绩数量

  2. 询问用户获得的分数以及该分数的百分比 x 次,其中 x 是用户在第一个问题上给出的数字。

  3. 根据输入计算最终学期成绩。

我希望有人能提供帮助,到目前为止,我已经制作了这段代码,以防它帮助你理解我想要做什么。

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")

标签: python

解决方案


#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
  

推荐阅读