我有以下代码。当我输入一个字母字符“Scale = float(raw_input(”请输入'1'代表华氏温度,'2'代表摄氏温度:“))”在while循环中,我收到“ValueError:无法将字符串转换为float:s “错误。同时,当我按下需要的1或2时。我收到“输入了无效选项”,如果输入任何其他字符1或2,则会弹出该选项。你能帮我解决这个问题吗?非常感谢。
import socket, sys, os
Arguments = sys.argv
Host = (Arguments[1])
Port = (int(Arguments[2]))
try:
Server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Server.connect((Host,Port))
except socket.error, (value,message):
if Server:
Server.close()
print "Failed to create the socket: " + message
sys.exit(1)
while(True):
Scale = float(raw_input("Please enter '1' for Fahrenheit and '2' for Celsius: "))
if ((Scale != 1)) or ((Scale != 2)):
print ("\nInvalid option is entered.")
else:
Server.sendall(Scale)
break