0

Error in python practice solution?

My opinion, Nearest Restaurant practice in Introduction to Python the correct answear is for i in range(1, floors+1): But the solution says for i in range(1, floors): there is no output if the input is 5. This for loop never go to the last floor.

28th Jan 2023, 4:27 AM
Kukusik Péter
4 ответов
+ 8
Kukusik Péter , the issue is not the for loop. > when using a range like: *range(3, 10)* the start number (3 ) is included in the range. the stop number (10) is excluded, so this range generates: 3, 4, 5, 6, 7, 8, 9 > for our case to get the stop number included we have to use: range(3, 10 +1)
28th Jan 2023, 12:14 PM
Lothar
Lothar - avatar
+ 2
Kukusik Péter Share the link of the problem
28th Jan 2023, 5:20 AM
R🍁🇮🇳
R🍁🇮🇳 - avatar
+ 1
The challenge: Nearest Restaurant A group of buildings has a restaurant on every 5th floor. In other words, a building with 12 floors has restaurants on the 5th and 10th floors. Task Create a program that takes the total number of floors as input and outputs the floors that have restrooms. Sample Input 17 Sample Output 5 10 15 Official solution: floors = int(input()) for i in range(1, floors): if i%5 == 0: print(i) I think this for loop wrong because never go to the last floor. The correct is for i in range(1, floors+1):
28th Jan 2023, 11:17 AM
Kukusik Péter