0
for and range
a = int(input()) b = int(input()) for i in range(a, b,): print(i) This is what I've got. When: Input - 2000, 2005 Expected output - [2000, 2001, 2002, 2003, 2004] But my output is - 2000 2001 2002 2003 2004 What's happening??😥
6 Réponses
+ 5
1. the expected output is a list
2. the print result default end with '\n'
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
+ 4
You were expected to create a list, but you print the numbers within the range instead
# using list() function
print( list( range( a, b ) ) )
# using list comprehension
print( [ year for year in range( a, b ) ] )
+ 4
a = int(input())
b = int(input())
numList = []
for i in range(a, b,):
numList.append(i)
print(numList)
+ 3
Thx guys!
+ Rakshit Sen Thx for yr message but I cannot activate my acc for some reason 😥 And yes, this is my little labradoodle in the profile pic, although she has gotten bigger now 😂