Home > Software engineering >  I want to make an calculator for average but i'm facing some issues
I want to make an calculator for average but i'm facing some issues

Time:05-15

I want to make an calculator for average but i'm facing some issues. I want the numbers entered by the users come as a print statement but it is just throwing the last entered value.Here is my code.

numlist = list()
while True:
    inp = input(f"Enter a number, (Enter done to begin calculation): ")
    if inp == 'done':
        break
    value = float(inp)
    numlist.append(value)
average = sum(numlist) / len(numlist)
print(f"The Entered numbers are: ", inp)
print(f"average is = ", average)

CodePudding user response:

Solution

we can print the list

numlist = list()
while True:
    inp = input(f"Enter a number, (Enter done to begin calculation): ")
    if inp == 'done':
        break
    value = float(inp)
    numlist.append(value)
average = sum(numlist) / len(numlist)
print(f"The Entered numbers are: {numlist}")
print(f"average is = ", average)

CodePudding user response:

As I understand, you want to print all the user inputs, however, as I see in your code, you are printing just a value but not the storing list, try to change your code to print(f"The Entered numbers are: ", numlist)

CodePudding user response:

You are telling the user that their entered numbers are the last thing they typed in input, which will always be "done" because that is what breaks out of the loop. If you want to print the entered numbers; print numlist instead of inp.

  • Related