+ 2

33.2 Nearest Bathroom Practice help

Getting the right output but wrong format. Not sure what to do. n = int(input()) n = list(range(0, n, 5)) print(n) A group of buildings have restrooms on every 5th floor. For example, a building with 12 floors has restrooms on the 5th and 10th floors. Create a program that takes the total number of floors as input and outputs the floors that have restrooms. Sample Input 23 Sample Output 5 10 15 20 You can define a range with the corresponding rules and output the numbers in that range. Remember, that range(a, b) includes a, but does not include b.

27th Mar 2021, 5:02 PM
Zach Z
20 Answers
+ 6
You can use a for loop instead of list(). Range should be started from 5 since 0 isn't included in sample output range(5,n,5)
27th Mar 2021, 5:29 PM
Simba
Simba - avatar
+ 5
thanks Simba. here is what worked. always a little surpised myself when it does. n = int(input()) for n in (range(5, n, 5)): print(n) thanks ChaoticDawg dont know how to do all of that but appreciate the options
28th Mar 2021, 7:56 PM
Zach Z
+ 3
You need to do the range as Simba stated. Then you can either use a for loop or list compression or use the unpack operator (*) and set the seperator value of the print function to a newline (sep='\n') to get the desired output.
27th Mar 2021, 8:02 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Zach Z A list comprehension will be similar to your for loop; [print(n) for n in range(5, int(input()), 5)] While using the unpack operator is a bit different. print(*range(5, int(input()), 5), sep='\n') You will learn a bit about each in the courses.
28th Mar 2021, 8:03 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
A group of buildings have restrooms on every 5th floor" stated in the question So if someone input 25 that means there must be a restroom in 25th floor, so to include 25th floor we have to use __________________________ n = int(input()) for n in (range(5, n+1, 5)): print(n)
4th Mar 2022, 3:38 AM
Sanjim Chowdhury
Sanjim Chowdhury - avatar
+ 2
First please create your attempt on SL Playground and provide the link here with you question.
27th Mar 2021, 5:23 PM
JaScript
JaScript - avatar
+ 2
n = int(input()) #your code goes here room=list(range(5,n,5)) for i in room: print(i) i+=1
20th Jul 2021, 9:40 AM
Sushant Kashikar
Sushant Kashikar - avatar
+ 2
Don’t forget the colon after the for loop…. 🤦🏻
9th Jan 2022, 9:03 PM
Quality Crew
Quality Crew - avatar
+ 1
n = int(input()) #your code goes here for bathroom in range(5,n,5): print (bathroom)
4th Apr 2021, 5:02 PM
Allan 🔥STORMER🔥🔥🔥🔥
Allan 🔥STORMER🔥🔥🔥🔥 - avatar
+ 1
n = int(input()) #your code goes here for i in range(5, n, 5): print(i)
2nd Jun 2021, 5:26 PM
Likhitha Ankinapalli
+ 1
Hi, did you get it?, I did the following but I only passed the first 4 tests, I still need the last one n = int(input()) #your code goes here nums= list(range (5,n,5)) for x in nums: print (x)
21st Jul 2022, 4:06 PM
Yunuen Sarasuadi Acosta Meza
Yunuen Sarasuadi Acosta Meza - avatar
+ 1
I tried same code, n = int(input()) for a in range(5,n,5): print (a) but the last one, case 5 is not working! Kindly assist if anyone was able to solve this
22nd Jul 2022, 9:56 PM
Kaustubh KR
Kaustubh KR - avatar
+ 1
hey ppl here is my coden = int(input()) #your code goes here room=list(range(5,n,5)) for i in room: print(i) i+=1 but still case 5 does not works,i stuck badly here :/
23rd Jul 2022, 6:07 PM
Kubilay Ada
Kubilay Ada - avatar
+ 1
Hi all i have the same issue: Test case 5 allways fails and i dont understand why? Code: n = int(input()) #your code goes here floors = list(range(5,n,5)) for bathroomfloor in floors: print(bathroomfloor)
24th Jul 2022, 3:04 PM
Lucas Graversen
Lucas Graversen - avatar
+ 1
Sanjim had the correct answer I was looking for to get test case 1 through 4 but also case 5. Can someone please explain to me though why it's range(5, n+1, 5) and not range(5, n, 5)?
26th Jul 2022, 7:09 PM
inglomi
inglomi - avatar
+ 1
The solution is incorrect. The range is (5, n+1, 5). Not (5,n,5) as the solution indicates. Remember that a list goes from (including) the first number to (excluding) the second number. So to include the 25th floor you need to increase the range
26th Jul 2022, 11:38 PM
Zaheer Hoosain
Zaheer Hoosain - avatar
0
Using the for loop will always start at 0. you can bypass this by adding a continue statement that simply tells the loop to skip this part of the range :) n = int(input()) #your code goes here numbers = list(range(0, n, 5)) for i in numbers: if(i==0): continue print(i)
18th Apr 2021, 9:19 PM
Leonard Baker
Leonard Baker - avatar
0
Hi. This is my code. Test cases 1 to 4 pass but test case 5 fails and I don't understand why. Please help: n = int(input()) for i in range(5, n, 5): print(i)
25th Jul 2022, 10:40 PM
Zaheer Hoosain
Zaheer Hoosain - avatar
0
I think my code is also easy and understandable. n = int(input()) for n in range(1,n): if(n % 5 == 0): print(n) Good luck!
5th Aug 2022, 11:58 AM
Abdul Ghafar
Abdul Ghafar - avatar
- 1
you are very close with you attempt. as Simba stated in his post, you will need to use a for loop. the code would like something like this: n = int(input()) # the underscore is a placeholder instead of using a letter as a variable for _ in range(0, n, 5): print(_)
27th Mar 2021, 6:13 PM
you are smart. you are brave.
you are smart. you are brave. - avatar