In: Computer Science
Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.
python:
Code:
#count to store the number of valid inputs
count=0
#highdcore
highscore=-1
#low score
lowscore=100
#variable to store sum
s=0
#an infinite loop which only breaks when 99 is entered
while(True):
#taking input
num=int(input("Enter Quiz score "))
#checking if it is 99
if(num == 99):
break
#if it is not between 0 and 10
if(num<0 or num>10):
print("Score must be between 10 and
0")
#starting again from the loop
continue
#incrementing count
count=count+1
#adding num to sum
s=s+num
#getting highscore
if(highscore<num):
highscore=num
#getting lowscore
if(lowscore>num):
lowscore=num
#finding average
avg=s/count
#printing results
print("Average is "+str(avg))
print("Highest score is "+str(highscore))
print("Lowest score is "+str(lowscore))
print("Count is "+str(count))
Output:
Code Screenshot:
Code Snippet:
#count to store the number of valid inputs
count=0
#highdcore
highscore=-1
#low score
lowscore=100
#variable to store sum
s=0
#an infinite loop which only breaks when 99 is entered
while(True):
#taking input
num=int(input("Enter Quiz score "))
#checking if it is 99
if(num == 99):
break
#if it is not between 0 and 10
if(num<0 or num>10):
print("Score must be between 10 and 0")
#starting again from the loop
continue
#incrementing count
count=count+1
#adding num to sum
s=s+num
#getting highscore
if(highscore<num):
highscore=num
#getting lowscore
if(lowscore>num):
lowscore=num
#finding average
avg=s/count
#printing results
print("Average is "+str(avg))
print("Highest score is "+str(highscore))
print("Lowest score is "+str(lowscore))
print("Count is "+str(count))
java:
code:
//importing this package as we are using Scanner class
import java.util.*;
//class name is Quiz score so, file should be saved as
QuizScore.java
class QuizScore{
//main method
public static void main(String[] args) {
Scanner s = new
Scanner(System.in);
//declaring variables
int count=0;
int high=-1;
int low=100;
int sum=0;
float avg;
int num;
//an infinite loop which onl breaks
when 99 is entered
while(true){
//taking
input
System.out.println("Enter Quiz Score");
num=s.nextInt();
//checking if it
is 99
if(num==99){
//if 99 is entered break
break;
}
//checking if
the number is not between 10 and 0 or not
if(num<0 ||
num>10){
//if it is not then starting loop again
System.out.println("Score must be between 10 and
0");
continue;
}
//incrementing
count
count++;
//adding num to
sum
sum=sum+num;
//finding
highest and lowest
if(high<num){
high=num;
}
if(low>num){
low=num;
}
}
//finding average and printing
results
avg=sum/count;
System.out.println("Average is
"+avg);
System.out.println("Highest score
is "+high);
System.out.println("Lowest score is
"+low);
System.out.println("Count is
"+count);
}
}
Output:
Code Screenshot:
Code Snippet:
//importing this package as we are using Scanner class
import java.util.*;
//class name is Quiz score so, file should be saved as QuizScore.java
class QuizScore{
//main method
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
//declaring variables
int count=0;
int high=-1;
int low=100;
int sum=0;
float avg;
int num;
//an infinite loop which onl breaks when 99 is entered
while(true){
//taking input
System.out.println("Enter Quiz Score");
num=s.nextInt();
//checking if it is 99
if(num==99){
//if 99 is entered break
break;
}
//checking if the number is not between 10 and 0 or not
if(num<0 || num>10){
//if it is not then starting loop again
System.out.println("Score must be between 10 and 0");
continue;
}
//incrementing count
count++;
//adding num to sum
sum=sum+num;
//finding highest and lowest
if(high<num){
high=num;
}
if(low>num){
low=num;
}
}
//finding average and printing results
avg=sum/count;
System.out.println("Average is "+avg);
System.out.println("Highest score is "+high);
System.out.println("Lowest score is "+low);
System.out.println("Count is "+count);
}
}
C:
Code:
#include<stdio.h>
//main function
int main(){
//declaring and initializing variables
int count=0;
int high=-1;
int low=100;
int sum=0;
int num;
//an infinite loop which only breaks when 99 is
entered
while(1){
//takng user input
printf("Enter Quiz score: ");
scanf(" %d",&num);
//if num is 99 loop
terminates
if(num==99){
break;
}
//if num is not between 0 and 10
loop starts again
if(num<0 || num>10){
printf("Score
must be between 10 and 0\n");
continue;
}
//increment count
count++;
//adding num to sum
sum=sum+num;
//finding highest and lowest
if(high<num){
high=num;
}
if(low>num){
low=num;
}
}
//finding average
float avg=sum/count;
//printing results
printf("Average is %.2f\n",avg);
printf("Highest score is %d\n",high);
printf("Lowest Score is %d\n",low);
printf("The count is %d",count);
}
Output:
Code Screenshot:
Code Snippet:
#include<stdio.h>
//main function
int main(){
//declaring and initializing variables
int count=0;
int high=-1;
int low=100;
int sum=0;
int num;
//an infinite loop which only breaks when 99 is entered
while(1){
//takng user input
printf("Enter Quiz score: ");
scanf(" %d",&num);
//if num is 99 loop terminates
if(num==99){
break;
}
//if num is not between 0 and 10 loop starts again
if(num<0 || num>10){
printf("Score must be between 10 and 0\n");
continue;
}
//increment count
count++;
//adding num to sum
sum=sum+num;
//finding highest and lowest
if(high<num){
high=num;
}
if(low>num){
low=num;
}
}
//finding average
float avg=sum/count;
//printing results
printf("Average is %.2f\n",avg);
printf("Highest score is %d\n",high);
printf("Lowest Score is %d\n",low);
printf("The count is %d",count);
}