新手求助,请问为什么我输入guess=int(temp)的时候,就报错了呢?
新手求助,请问为什么我输入guess=int(temp)的时候,就报错了呢?Python 3.8.2rc2 (v3.8.2rc2:777ba072d6, Feb 17 2020, 21:37:25)
on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> print('------------玩游戏-----------')
------------玩游戏-----------
>>> temp=input("是几")
是几
>>> guess=int(temp)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
guess=int(temp)
ValueError: invalid literal for int() with base 10: ''
>>> 你这是idle
在里面按Ctrl+n
打开一个源文件
之后保存
run它 https://www.cnblogs.com/jack-zh/p/10808171.html
看看这篇文章 本帖最后由 wuqramy 于 2020-3-24 09:11 编辑
1.如果你要编程序,就要在IDLE里面打开一个新窗口(Ctrl + n),在里面写代码
2.回答你的问题:因为temp是字符串不可以化整(int()),只有浮点形(float)和整形(int)可以使用int()方法 第一步:使用IDLE新建一个文件(Ctrl+N)
第二步:保存,然后把代码拷贝进去。 因为 int() 无法将一个不是数字的字符串变成整形:
>>> int("")
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
int("")
ValueError: invalid literal for int() with base 10: ''
页:
[1]