-1

I am creating a calculator and I place the numbers taken by the user into a list.I had to make the input a string since I place the input in a while loop and gave it a string to break the loop (q).

while True:
    numbers = input('Enter the numbers for calculation: ')
    if numbers == 'q':
        break
    operations.append(numbers)

I want to turn the list where the user's input is kept into a float so that I can perform operations on them. This is the list: operations = []

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 4
    `operations.append(float(numbers))` assuming you are introducing the numbers one by one and they are indeed valid numbers (except for the "q" character) –  Feb 18 '22 at 19:24
  • Does this answer your question? [How do I parse a string to a float or int?](https://stackoverflow.com/questions/379906/how-do-i-parse-a-string-to-a-float-or-int) – Jay Feb 18 '22 at 19:25

1 Answers1

0

I'm still learning Python, so don't judge too harshly.

operations = []
while:
    number = input('Enter number\n')

    if number == 'q':
        print('QUIT')
        break
    else:
        number = float(int(number))
        operations.append(number)
        print(operations)

I just couldn't make a check for the input of any other letters, except for "q"