Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I've got a tiny project I'm working on: I'm trying to make a "grading" program that lets you enter the number of exams, the scores for each exam, and then print's the results.

What I'm looking to do:

Enter the number of tests: use that number with the string "Exam #: " to number each test.

I've gotten as far as sticking the input from "Enter the number of tests:" into a list..(looks like [0,1,2,3,4.. etc] now I'm trying to combine each of those list numbers with the above string and nothing I'm trying is working.. suggestions?

This is what I came up with, and its output:

test1 = int(input('How many tests are there? '))

test2 = []

for number in range(test1):

    test2.append(number)

for number2 in test2:

    print('Exam #:' + str(number2))

(inputting "5" here)

Exam #:0

Exam #:1

Exam #:2

Exam #:3

Exam #:4

exactly what I needed!

1 Answer

0 votes
by (36.8k points)

Try  this

num_exams = int(input('Enter the number of exams: '))

exam_scores = [int(input(f'Enter score for exam #{n+1}: ')) for n in range(num_exams)]

print(f'Average score: {sum(exam_scores) / num_exams:0.2f}')

 If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...