Issue
I want to add a loop to the end of another loop. But all I've tried failed and I don't know what to do
I've tried
for i in range(2):
print i
for r in range(4, 6):
print i.append(r)
and
for i in range(2):
print i
print i.append(4,5)
I expected:
0
1
4
5
But I received the following error instead:
Error for the 1st code sample:
Traceback:(most recent call last):
File "main.py", line 4, in <module>
print i.append(r)
AttributeError: 'int object has no attribute 'append'
Error for the 2nd code sample:
Traceback:(most recent call last):
File "main.py", line 4, in <module>
print i.append(4, 5)
AttributeError: 'int object has no attribute 'append'
Solution
This code produces the output you seem to require:
for i in range(2):
print i
for r in range(4, 6):
print r
Answered By - quamrana
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.