Question: Using Python. Having trouble getting the output to only contain 1 decimal place for some figures and 2 decimal point for the 4.33 figure. #
Using Python. Having trouble getting the output to only contain 1 decimal place for some figures and 2 decimal point for the 4.33 figure.

# Python code # for random number import random # Set the random seed to 108 random.seed(108) # Ask user enter the number of readings N = int(input('Please input the number of readings: ')) # Initialize variable to keep track of the sum of all the drawn numbers so far total = 0.0 # Loop used for drawing a new random number on each iteration and updating the average for i in range(1, N + 1): # Draw a new random number from 0 to 10 no = random.randint(0, 10) # Update the running total using the formula for the new average total = (total * (i - 1) + no) / i # Print the new reading and the current average print(f'New reading: {no}') print(f'Current_average: {total:.1f}') # Print the final average print(f'Final average: {total:.2f}')
Precheck onlv
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
