
Michael S. answered 12/22/22
Software Engineer
# Open a file for writing
f = open("numbers.txt", "w")
# Initialize a variable to store the sum
sum = 0
# Continuously prompt the user for input
while True:
# Get the user's input
num = input("Enter a number: ")
# If the user just hits Enter, break out of the loop
if num == "":
break
# Convert the input to a float and add it to the sum
sum += float(num)
# Write the number to the file
f.write(num + "\n")
# Close the file
f.close()
# Print the sum
print("The sum of your numbers is", sum)