1

(I am barely starting out coding in Python and this is my first time using stack overflow)

Today I was making a conversion calculator (lbs to Kg) but the code doesn't return anything. Here is the code:

question = int(input("Enter input(lbs) here = "))

while question == int:
    
     equation = question/2.20462262
     print(equation)

While the question(line 3) appears, when I type a int number in, it doesn't return anything and the code simply ends. (Please do forgive any mistakes I may have made with this post/and just silly mistakes in the code. I'm learning everyday and I do hope I can get better!)

Illusion705
  • 451
  • 3
  • 13
  • you should check for Type(question) ==int – Rima Mar 06 '21 at 23:58
  • Does this answer your question? [How to determine a Python variable's type?](https://stackoverflow.com/questions/402504/how-to-determine-a-python-variables-type) – Montgomery Watts Mar 06 '21 at 23:58
  • 1
    Does this answer your question? [How to check if string input is a number?](https://stackoverflow.com/questions/5424716/how-to-check-if-string-input-is-a-number) – Gino Mempin Mar 07 '21 at 00:06
  • try to amend your condition `question == int`, in your current logic "an integer"==int will never be True – Benjaminliupenrose Mar 07 '21 at 01:58

2 Answers2

1

your logic is wrong, you seem to want to keep asking as long as an integer is given.

In your current logic, you only ask once and then if it's an int, it would just keep printing forever.

Instead do something like:

while True:
    try:
        question = int(input("Enter input(lbs) here = "))
    except ValueError: 
        break
    
    equation = question/2.20462262
    print(equation)
DevLounge
  • 8,313
  • 3
  • 31
  • 44
0

while loop does not exit and runs infinitely. you should write a condition to exit your while loop.

question=''
while question != 'quit':
    question = input("Enter input(lbs) here or type 'quit' to exit = ")
    if question != 'quit':
        equation = int(question)/2.20462262
        print(equation)
Rima
  • 1,447
  • 1
  • 6
  • 12