using python Assign grades) Write a program that reads a list of scores and then
ID: 3775331 • Letter: U
Question
using python
Assign grades) Write a program that reads a list of scores and then assigns grades based on the following scheme:
The grade is A if score is best – 10.
The grade is B if score is best – 20.
The grade is C if score is best – 30.
The grade is D if score is best – 40.
The grade is F otherwise.
Here is a sample run:
Enter scores: 40 55 70 58
Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B
Explanation / Answer
import java.util.Scanner;
public class ProgrammingEx7_1 {
public static void main(String[] args) {
System.out.print("Enter the number of students:");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] score = new int[n];
int bestScore = 0;
System.out.print("Enter " + n + " scores:");
for (int i = 0; i < score.length; i++) {
score[i] = input.nextInt();
if (bestScore < score[i]) {
bestScore = score[i];
}
}
char grade;
for (int i = 0; i < score.length; i++) {
if (score[i] >= bestScore - 10)
grade = 'A';
else if (score[i] >= bestScore - 20)
grade = 'B';
else if (score[i] >= bestScore - 30)
grade = 'C';
else if (score[i] >= bestScore - 40)
grade = 'D';
else
grade = 'F';
System.out.println("Student " + i +" score is " + score[i] +" and grade is " + grade);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.