0

I am begineer at coding in python and i am trying to create a simple calculator.I want the code to repeat it self an quit when i type in "q".But the output gave an error ""

Here is the code

while True:
    nums=float(input('Enter numbers for calculations'))
    if str(nums) == 'q':
        break
    operation.append(nums)

Here is the error it gave:

 * nums=float(input('Enter numbers for calculations'))
ValueError: could not convert string to float: 'q'*
j1-lee
  • 13,764
  • 3
  • 14
  • 26
  • https://stackoverflow.com/questions/379906/how-do-i-parse-a-string-to-a-float-or-int – ENCS16 Feb 17 '22 at 19:49
  • 1
    Of course, you're converting whatever you input to a float. So if you input `'q'`, it will try to convert it to a float, which fails. Try checking for `'q'` before converting to a float – Mateo Vial Feb 17 '22 at 19:49

1 Answers1

0

because the input() is already a string by definition if you put a "float" inside it, it will turn it into a string right away so:

while True:
    x= input('Enter numbers for calculations')
    if x == 'q':
        break
print(x)

will make it repeat itself and when you type q it will stop

Raz Asido
  • 28
  • 1