Help to understand and write program to calculate average

yeeehaaaa, I did it… :partying_face: :partying_face: :partying_face: :joy: :joy: :poop: :poop:
What people think about this…
many thanks to you all and special thanks to @anon40284853.

request = float(0) #trying with float
numbers = float(-1)
count = []

print("enter a numbers different then -1 ")
request = input("or -1 to calculate the average: ")
# request = input("number: ")
request = float(request)
while request != numbers:
  count.append(request)
  request = input("enter anothe number or -1 to calculate the average: ")
  request = float(request)

request = float(request)
# count = int(count)
average = sum(count)/len(count)
print("the average is: ",average)
2 Likes

It is somewhat complicated, but it is a good effort! Congrats!

@whileTRUEpass you think is complicated :thinking::thinking:
I thought I was writing it quite simple, step by step, without complicated lines where a beginner gets lost because need to disassemble the line.
I still don’t know when and how to convert the variables to make it work, that is why I do it several times, because once I make an input it changes to str so i had to change again… well, next time will be better code…:grin::grin:
Could you please show me other way to write the program. Please

Do not worry. It is a good effort. Asyou keep programming, and learn more, do it again and you will understand. Unfortunately, programming is 30% shown/read and 70% practice :slight_smile:

I did show you a shorter way in your private message. If you would like I can shrink that program down but that would reduce readability. In fact I just learned yesterday about the walrus operator := which could help make this smaller.

The code I supplied
numbers = [] # Create an empty list
while str(input("Would you like to add another number?\n")).lower() in ["y", "yes", ""]: # If the lowercase of the user's input is in the list of yes:
  numbers.append(float(input("\nPlease enter a number, whole or decimal: "))) # Add the float of the user's input to the list
print(f"\nYour average is {sum(numbers)/len(numbers)}.") # Display the average of the numbers. It is the sum of the list divided by the number of items in the list.
# Other stuff to note: "\n" is the ANSI sequence to add a new line. "len" gathers the number of items in a list. "sum" finds the sum of the items in a list. ".lower()" makes the entire string lowercase.

And here it is if you want to end it on -1:

numbers = []
while str(input("Would you like to add another number?\n")) in ["y", "yes", ""]:
  number = float(input("\nPlease enter a number, whole or decimal: ")) # Get user's number
  if int(number) == -1: # If the number is -1:
    break # End loop
  numbers.append(number) # Otherwise, add number to list "numbers"
print(f"\nYour average is {sum(numbers)/len(numbers)}.")

yes @anon40284853 you did sent me the code.