python 错误提示TypeError: unsupported type 35operand type(s) for //: 'str' and 'int'

Access denied | www.bkjia.com used Cloudflare to restrict access
Please enable cookies.
What happened?
The owner of this website (www.bkjia.com) has banned your access based on your browser's signature (4306ccb-ua98).python 小问题_百度知道
python 小问题
n=inputn=n+1print (n)TypeError: unsupported operand type(s) for +: 'builtin_function_or_method' and 'int'
我有更好的答案
input是个方法 要加括号n=input
这个返回的n是str类型而n+1
1是int类型 所以把n转换成int型 n=input 改成n=int(input())
采纳率:76%
改成 print n
应该是n=input()
n&=&int(input())n&=&n&+&1print&(n)
n = n+1有问题n是方法引用,不能使用+操作!
其他2条回答
为您推荐:
其他类似问题
您可能关注的内容
python的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。python release dll, can't capture error output | C Programming | Python | Software Architecture
python release dll, can't capture error output
I have a C++ program that captures and displays the syntax or runtime error information when a python script is run. It works when compiled with the debug python dll, [url removed, login to view], but not with the realease dll. Another programmer working on the project tod me this has something to do with the dll itself.
## Deliverables
here is some of the code showing how input is captured:
//set up error and print catching, do this first so that any following error will be caught
PyRun_SimpleString(&import ograb72984&);
PyRun_SimpleString(&import sys&);
PyRun_SimpleString(&class a7198429:\n\tdef write(self,s):\n\t\[url removed, login to view](s)\n&);//output-grabber class, funny name to prevent ambiguity with user-defined classes
PyRun_SimpleString(&sys.stderr=a7198429()\nsys.stdout=a7198429()&); //\n&);
//////////////////////py grabber
include &pyinc.h&
#include &AutoCore.h&
#include &PyMethsGrabber.h&
extern AutoCore A
//used to capture python stderr and stdout streams
//equivilent to [url removed, login to view], [url removed, login to view] not used becasue would require importing tp module in globab interpreter, now only small module needs importing, see AutoCore::AutoCore()
static PyObject* ograb(PyObject *self, PyObject *args)
if(!PyArg_ParseTuple(args, &s&, &s))
return NULL;
[url removed, login to view](s);
Py_INCREF(Py_None);
return Py_N
static PyMethodDef ograbMeths[] =
{&ograb&, ograb, METH_VARARGS, NULL},
void InitGrabberMeths()
Py_InitModule(&ograb72984&, ograbMeths);
63 reviews
Tallahassee, United States
Your email address
Set your budget and timeframe
Outline your proposal
Get paid for your work
It's free to sign up and bid on jobs
It's free to sign up, type in what you need & receive free quotes in seconds
Enter your project description here
Post a Project
I am a new user
I am a returning userpython3.4这句话不能运行_百度知道
python3.4这句话不能运行
我看书上的,但是运行不了
values = range(1,11) + 'Jack Queen King'.split()
应该怎么改
&&& values = range(1,11)+'jack queen king'.split()
Traceback (most recent call last):
File &&stdin&&, line 1, in &module&
TypeError: unsupported op...
我有更好的答案
&&& a = range(1, 10)&&& type(a)&class 'range'&&&& values = list(range(1,11)) + 'jack queen king'.split()&&& values[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'jack', 'queen', 'king']在Python 3中,range 产生一个可迭代的range对象,它不是一个列表。所以,要先生成一个列表,再向其中追加元素。
采纳率:80%
来自团队:
为您推荐:
其他类似问题
您可能关注的内容
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。原创by南山南北秋悲
欢迎引用!请注明原地址:& 谢谢!
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'
打印变量时遇到的问题,
想着c语言中printf("%s", 变量名)
python中 应该也是类似的语句
果断百度,发现是通过语句后附加一个%(变量名)来解决的
详细如下:
print语句可以使用跟着%符号的项目元组的字符串。这些字符串具备定制的功能。定制让输出满足某种特定的格式。定制可以是%s表示字符串或%d表示整数。元组必须按照相同的顺序来对应这些定制。
观察我们使用的第一个元组,我们首先使用%s,这对应变量name,它是元组中的第一个项目。而第二个定制是%d,它对应元组的第二个项目age。
Python在这里所做的是把元组中的每个项目转换成字符串并且用字符串的值替换定制的位置。因此%s被替换为变量name的值,依此类推。
print的这个用法使得编写输出变得极其简单,它避免了许多字符串操作。它也避免了我们一直以来使用的逗号。
在大多数时候,你可以只使用%s定制,而让Python来提你处理剩余的事情。这种方法对数同样奏效。然而,你可能希望使用正确的定制,从而可以避免多一层的检验程序是否正确。
在第二个print语句中,我们使用了一个定制,后面跟着%符号后的单个项目&&没有圆括号。这只在字符串中只有一个定制的时候有效。
age =&22name =&'Swaroop'print&'%s is %d years old'&% (name, age)print&'Why is %s playing with that python?'&% name
Swaroop is 22 years oldWhy is Swaroop playing with that python?
可是我自己编程的时候却遇到了上述问题:TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'
语句如下:
a = 'Peter'b = 'Linda'print("who is the murder? %s or %s?") % (a, b)后来才发现,python3.x与python2.x有一点区别,原来%(变量名,...)应该是加在print括号里的如:print("who is the murder? %s or %s" % (a, b))改完以后输出正常:
阅读(...) 评论()

我要回帖

更多关于 unsupportedmediatype 的文章

 

随机推荐