So, I've been having a problem while trying to convert the variable t into a float, and it's giving me an error, saying "could not convert string to float: " with a space as false.
def FtoC(a):
a=(t-32)*1.8
return a
def FtoK(a):
a=(a-32)*1.8+273
return ta
def CtoF(a):
a=a*1.8+32
return a
def CtoK(a):
a=a+273
return t
def KtoC(a):
a=a-273
return a
def KtoF(a):
a=(a+459.67)*5/9
return a
########################################################
import re
t=input()
while True:
if t=='end':
break
tl=list(t)
t=re.findall('\d+', t)
t=''.join(t)
t=float(t)
if tl[-1]!='C' or tl[-1]!='K' or tl[-1]!='F' or t>200 or t<-100:
print("Wrong")
else:
if tl[-1]=='C':
print("%.2f" % t,'C',CtoF(t),'F',CtoK(t),'K')
if tl[-1]=='K':
print("%.2f" % t,'K',KtoC(t),'C',KtoF(t),'F')
if tl[-1]=='F':
print("%.2f" % t,'F',FtoC(t),'C',FtoK(t),'K')
t=input()
I've been testing out with print commands inbetween and it prints the float value just alright, but in the if command it shows up an error, so it just prints "Wrong" every single time. When I remove:
if tl[-1]!='C' or tl[-1]!='K' or tl[-1]!='F' or t>200 or t<-100:
print("Wrong")
The code works jus fine. Where is the problem?
I've been running the program on a private university platform, and this is what it returns:
Non-zero exitcode 1
*** Program stderr output following ***
Traceback (most recent call last):
File "my_code.py3", line 28, in
t=float(t)
ValueError: could not convert string to float:
When using Python it just prints "Wrong", without any error.