Home>Article>Backend Development> How to input grades and calculate average scores in python script?

How to input grades and calculate average scores in python script?

coldplay.xixi
coldplay.xixi Original
2020-06-11 17:09:08 11877browse

How to input grades and calculate average scores in python script?

How does the python script input grades to calculate the average score?

How to input scores and calculate average scores in python script:

The script needs to implement the function:

1. Enter the student ID number:

2. Enter the student's grades in three subjects in sequence:

3. Calculate the student's average grade and print it:

4. Keep the average grade to two decimal points:

Calculate the student’s Chinese score as a percentage of the total score and print it.

Implementation code:

#学号输入 Student_Id = input('请输入学号: ') #科目成绩输入 Chinese_Score = int(input('请输入语文科目成绩: ')) Math_Score = int(input('请输入数学科目成绩: ')) English_Score = int(input('请输入英语科目成绩: ')) #总成绩计算 All_Score = Chinese_Score + Math_Score + English_Score #平均成绩 Average_Score = All_Score / 3 #百分比 Chinese_Percent = Chinese_Score / All_Score *100 print('%s的平均成绩为%.2f' %(Student_Id,Average_Score)) print('%s的语文成绩占总成绩的百分比为:%.2f' %(Student_Id,Chinese_Percent))

How to input grades and calculate average scores in python script?

How to input grades and calculate average scores in python script?

Note content:
1. The content we input manually is characters , variable type conversion needs to be performed to convert it into an integer or floating-point number.
2. Leave a space on both sides of the operation symbol
3.' ' is usually a string
4. When printing output, the format is similar to the C language. When multiple variables are involved, multiple variables use a %, write everything in one (), separated by commas

Recommended tutorial: "pythonVideo Tutorial

The above is the detailed content of How to input grades and calculate average scores in python script?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn