im having problems getting this follow program working as I would like it to. I have one step that is bothering me, I'll quickly go over what works first.
The program takes 2 arguments, pressure and unit, if pressure is an integer and the unit is "pascal","torr","atm" or "mbar" I want it to return "pressure=",pressure,unit. This works. If I dont enter a correct unit, I want the function to print "'unit' is not an accepted unit", this works.
Problematic part: When the variable pressure is given a float as 35.2 or a string as "test" BUT I give the variable unit a correct unit such as mbar I get the output
Enter an integer and a unit(seperated by ,): 3045.2,mbar
'3045.2' is not an integer
'mbar' is not an accepted unit
Obviously this is not working like I would want it to, 'mbar' is an accepted unit. Any help would be greatly appreciated. EDIT: Im quite new to programming overall so keep that in mind please :X
The program I have written:
pressure, unit = input("Enter an integer and a unit(seperated by ,): ").split(',')
def func(pressure, unit):
try:
pressure=int(pressure)
except ValueError:
print("'"+pressure+"'" + " is not an integer")
if(isinstance(pressure,int) and (unit == "pascal" or unit == "mbar" or unit == "atm" or unit == "torr")):
print("pressure =",pressure,unit)
elif(unit != "pascal" or unit != "mbar" or unit != "atm" or unit != "torr"):
print("'"+unit+"'" + " is not an accepted unit")
func(pressure, unit)