'Basic Python if statement logic [duplicate]
Can someone tell me why the code executes the first if statement and not the second one when I enter "p" into the console in python? I expect it to print out the second statement of 45.45
weight = 100 #int(input("Weight "))
conversion = input("kilograms or pounds: ")
if conversion in "k" or "K":
print(weight * 2.2)
elif conversion in "p" or "P":
print(weight // 2.2)
output:
kilo or pounds: p
220.00000000000003
Solution 1:[1]
try this
weight = 100 #int(input('Weight '))
conversion = input('kilograms or pounds: ')
if conversion in ['k','K']:
print(weight * 2.2)
elif conversion in ['p','P']:
print(weight // 2.2)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marcio Rocha |
