Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.6输入崩溃_Python_Python 3.x - Fatal编程技术网

Python 3.6输入崩溃

Python 3.6输入崩溃,python,python-3.x,Python,Python 3.x,我正在制作一台摄氏到华氏度的计算机,但是当我接受用户的输入时,程序崩溃了 我尝试使用raw_输入,但我得到了python3.6 print("Enter Celsius degrees to convert them into Fahrenheit degrees: ") x = input() y = x * 9 / 5 + 32 print(y) input() 它应该接受输入,然后自动将其转换为华氏度,然后打印华氏度。函数input()只返回字符串。即使键入数字,变量x中的值也将是字符串

我正在制作一台摄氏到华氏度的计算机,但是当我接受用户的输入时,程序崩溃了

我尝试使用raw_输入,但我得到了python3.6

print("Enter Celsius degrees to convert them into Fahrenheit degrees: ")
x = input()
y = x * 9 / 5 + 32
print(y)
input()
它应该接受输入,然后自动将其转换为华氏度,然后打印华氏度。

函数input()只返回字符串。即使键入数字,变量x中的值也将是字符串。 例如,键入20作为输入。x==“20”将为真,但x==20将为假。因此,必须将x转换为int或float,才能使用x进行算术运算。你可以在两个地方做

  • 从输入读取数据时
    x=float(输入())

  • 或者当您使用x将摄氏度转换为华氏度时
    y=float(x)*9/5+32


  • 到底发生了什么?我的意思是,我知道,但一个好问题会详细说明实际结果和预期结果。您的问题是
    input
    返回一个字符串。您需要执行:
    x=float(input())
    来解决问题
    input()
    函数返回
    string
    。你可以施放它谢谢。我不知道输入总是返回字符串。你解决了我的问题。