Computer Science - Computer Science
Nested Loop – Test ScoresCreate a program a teacher could use to get the average of each student’s test scores. The statement in line 3 asks the user for the number of students, and the statement in line 5 asks the user for the number of test scores per student. The for loop that begins in line 7 iterates once for each student. The nested inner loop, in lines 13 through 17, iterates once for each test score.# This program averages test scores. It asks the user for the number of students and number of scores per student# Get number of studentsnum_students = int(input('How many students do you have? '))# Get the number of test scores per studentnum_test_scores = int(input('How many test scores per student? '))# Determine each student’s average test scorefor student in range(num_students): # Initialize an accumulator for test scores total = 0.0 # Get a student’s test scores print('Student number', student + 1) print('---------------------------------------------') for test_num in range(num_test_scores): print('Test number', test_num + 1, end=' ') score = float(input(': ')) #add the score to accumulator total += score # Calculate the average test score for this student average = total / num_test_scores # Display the average print('The average for student number', student + 1, 'is: ', average) print()Program modified to get total average for all tests:# This program averages test scores. It asks the user for the number of students and number of scores per student# Get number of studentstotal_average = 0.0num_students = int(input('How many students do you have? '))# Get the number of test scores per studentnum_test_scores = int(input('How many test scores per student? '))# Determine each student’s average test scorefor student in range(num_students): # Initialize an accumulator for test scores total = 0.0 # Get a student’s test scores print('Student number', student + 1) print('---------------------------------------------') for test_num in range(num_test_scores): print('Test number', test_num + 1, end=' ') score = float(input(': ')) #add the score to accumulator total += score # Calculate the average test scorefor this student average = total / num_test_scores total_average = average + total_average # Display the average print('The average for student number', student + 1, 'is: ', average) print()print('The average for all tests is: ', total_average/num_students) ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- home computer science and engineering
- lab noland s baker college e portfolio home
- week 2 for loops and while loops
- student lab 1 input processing and output
- hunter college csci127 introduction to computer science
- computer science computer science
- activity sheet 6 python programing and while loops
- activity sheet 5 python programming and loops
Related searches
- igcse computer science workbooks pdf
- igcse computer science workbook
- igcse computer science workbook answer
- igcse computer science coursebook pdf
- computer science people
- what is computer science like
- computer science revision
- igcse computer science revision notes
- college computer science project ideas
- ideas for computer science project
- computer science projects for students
- computer science final project