- 帖子
- 5
- 精华
- 0
- 积分
- 22
- 阅读权限
- 10
- 注册时间
- 2019-1-8
- 最后登录
- 2019-8-8
|
本帖最后由 欲之 于 2019-1-10 17:57 编辑
- x,y=int(input("请输入坐标"))
- if x>0:
- if y>0:
- a="(%d,%d)在第一象限" %(x,y)
- else:
- a="(%d,%d)在第四象限" %(x,y)
- else:
- if y>0:
- a="(%d,%d)在第二象限" %(x,y)
- else:
- a="(%d,%d)在第三象限" %(x,y)
- print(a)
复制代码 这是教程里的一个练习题,但教程里的方法是每次输入一个值,然后分别判断。我想可不可以直接输入一个类似坐标的形式的值,然后程序会从输入的坐标里获取数值并作出判断呢?
上面代码执行后出现的问题:
{
"resource": "/C:/Workspace/python/draft6.py",
"owner": "python",
"code": "E0633",
"severity": 8,
"message": "Attempting to unpack a non-sequence",
"source": "pylint",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 1
}
这是控制台给出的提示:
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) File "c:\Users\Youlan\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\_vendored\pydevd\pydevd.py", line 1290, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "c:\Users\Youlan\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "c:\Workspace\python\draft6.py", line 1, in <module>
x,y=int(input("请输入坐标"))
ValueError: invalid literal for int() with base 10: '4,5'
(论坛的编辑器有点不好用呀 -_-||)
|
|