I'm trying to make a temperature converter. It convert Celsius to Fahrenheit and vice versa. The code I wrote is:
user_input = input("Insert the temperature you would like to convert: ")
user_num = user_input.replace('F' or 'C', '')
user_temp = float(user_num)
if ('F' in user_input or 'f' in user_input):
print(((user_temp - 32) * 5/9), 'C') # conversion from F to C
elif ('C' in user_input or 'c' in user_input):
print(((user_temp * 9/5) + 32), 'F') # conversion fron C to F
else:
print("Try again.")
'F' or 'C'<\/code> just evaluates to
'F'<\/code> .
I don't think this is what you want. You can either replace twice:
user_num = user_input.replace('F', '').replace('C', '')
user_num = user_input.replace('F' or 'C', '')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.