Jack Jack - 2 months ago 15
Python Question

If statement doesn't seem to be affecting my code.

units = input('Is your data in km/h or m/s: ')
if units == 'km/h' or 'KM/H' or 'Km/h' or 'kM/h' or 'km/H' or 'Km/H' or 'kM/h':
initialV = float(input('Enter the initial velocity:'))
finalV = float(input('Enter the final velocity: '))
deltaV = (initialV-finalV)

I want my code to, if the user inputs m/s for the units, to skip the indented code above, however, it doesn't seem to be happening as when running it, despite me putting m/s in the input, still, runs the above code.


You have to put the whole expression with "or".

if units == 'km/h' or units == 'KM/H' or units == 'Km/h' or units == 'kM/h' or units == 'km/H' or units == 'Km/H' or units == 'kM/h':