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
  • 383
  • 1
  • 12

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,127
  • 2
  • 29
  • 41
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)
ch2019
  • 1,353
  • 1
  • 5
  • 12