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??đŸ˜„

14th Jan 2022, 2:57 AM
Kaylee
Kaylee - avatar
4 Answers
+ 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)
14th Jan 2022, 3:08 AM
FanYu
FanYu - avatar
+ 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 ) ] )
14th Jan 2022, 3:30 AM
Ipang
+ 4
a = int(input()) b = int(input()) numList = [] for i in range(a, b,): numList.append(i) print(numList)
14th Jan 2022, 7:42 AM
Ghassan Al Khoury
Ghassan Al Khoury - avatar
+ 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 😂
14th Jan 2022, 2:47 PM
Kaylee
Kaylee - avatar