[英]how to remove unnecessary string or words from the user input
如果用戶給出了 90C 之類的輸入,它應該忽略 C
option=input("Please enter the convertion type: \n1.Celsius to Fahrenheit \n2.Fahrenheit to Celsius\n")
if option=="1":
Celsius=float(input("enter temperature in Celsius:"))
Fahrenheit=(Celsius*(9/5))+32
print("{0}°C is {1} in Fahrenheit".format(Celsius,Fahrenheit))
else:
Fahrenheit=float(input("please enter the temperature in Fahrenheit: "))
Celsius=(Fahrenheit-32)*(5/9)
print("{0}F is {1} in Celsius".format(Fahrenheit,Celsius))
如果用戶給出了 90C 之類的輸入,它應該忽略 C
option=input("Please enter the convertion type: \n1.Celsius to Fahrenheit \n2.Fahrenheit to Celsius\n")
if option=="1":
Celsius=float(input("enter temperature in Celsius:"))
Fahrenheit=(Celsius*(9/5))+32
print("{0}°C is {1} in Fahrenheit".format(Celsius,Fahrenheit))
else:
Fahrenheit=float(input("please enter the temperature in Fahrenheit: "))
Celsius=(Fahrenheit-32)*(5/9)
print("{0}F is {1} in Celsius".format(Fahrenheit,Celsius))
如果用戶給出了 90C 之類的輸入,它應該忽略 C
option=input("Please enter the convertion type: \n1.Celsius to Fahrenheit \n2.Fahrenheit to Celsius\n")
if option=="1":
Celsius=float(input("enter temperature in Celsius:"))
Fahrenheit=(Celsius*(9/5))+32
print("{0}°C is {1} in Fahrenheit".format(Celsius,Fahrenheit))
else:
Fahrenheit=float(input("please enter the temperature in Fahrenheit: "))
Celsius=(Fahrenheit-32)*(5/9)
print("{0}F is {1} in Celsius".format(Fahrenheit,Celsius))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.