Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> x=9
>>> while x>2:
x=x-2
print(x)
if x==1:
i=range(1,6)
j=range(1,i+1)
else:
i=range(5)
j=range(4)
7
5
3
1
Traceback (most recent call last):
File "<pyshell#2>", line 6, in <module>
j=range(1,i+1)
TypeError: unsupported operand type(s) for +: 'range' and 'int'
>>> i
range(1, 6)
>>> j
range(0, 4)
>>>
你的j=range(1,i+1)肯定不正确,i是range类,它不能与整形相加的
若你是要使j为1~7,可用
j=range(1,i.stop+1)
一周热门 更多>