Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i create a number of inputs from an input

I’m brand new to this, 10 days in.
Ive been thinking how I could solve this for 30 min. Please help.

Find Average

You need to calculate the average of a collection of values. Every value will be valid number. The average must be printed with two digits after the decimal point.

Input-

On the first line, you will receive N – the number of the values you must read
On the next N lines you will receive numbers.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Output-

On the only line of output, print the average with two digits after the decimal point.

Input
4
1
1
1
1
Output
1.00

Input 
3
2.5
1.25
3
Output
2.25

From what I see, I figure I need to create as much inputs as the N of the first one is and then input the numbers Id like to avarage and then create a formula to avarage them. I may be completely wrong in my logic, in any case Id be happy for some advice.

So far I tried creating a while loop to create inputs from the first input. But have no clue how to properly sintax it and continue with making the new inputs into variables I can use

a=int(input())
x=1
while x<a or x==a:
    float(input())
    x=x+1

>Solution :

a=int(input('Total number of input: '))

total = 0.0

for i in range(a):
    total += float(input(f'Input #{i+1}: '))
    
print('average: ', total/a)

Modified a bit on your version to make it work

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading