Exercise 3

Exercise 3
1 / 4
next
Slide 1: Slide
Ilearningdeal@gmail.comFurther Education (Key Stage 5)

This lesson contains 4 slides, with text slides.

time-iconLesson duration is: 5 min

Items in this lesson

Exercise 3

Slide 1 - Slide

Write a program that allows you to start with a value of 0 and then input a mark out of a 100, 5 times, each time the program adds the inputted number to the original starting value and then creates an average at the end.

.  
At the end the program should display the total of all the values and the average mark

Slide 2 - Slide

total_sum = 0

# Use a loop to input a mark 5 times
for i in range(5):
    # Ask for input and convert to a number
    mark = float(input(f"Enter mark {i+1} out of 100: "))
    # Add the inputted number to the original starting value
    total_sum += mark



# Create an average at the end
average_mark = total_sum / 5
# Display the total and the average mark
print(f"\nTotal of all values: {total_sum}")
print(f"Average mark: {average_mark}")

Slide 3 - Slide

# Start with a value of 0
total_marks = 0
# Input a mark 5 times
for i in range(1, 6):
    # Prompt the user for input
    mark = float(input(f"Enter mark {i} out of 100: "))
   




# Create an average at the end
average_mark = total_marks / 5
# Display the total of all values and the average mark
print(f"\nTotal Marks: {total_marks}")
print(f"Average Mark: {average_mark}")

Slide 4 - Slide