+ 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.
20 Respostas
+ 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)
+ 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
+ 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.
+ 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.
+ 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)
+ 2
First please create your attempt on SL Playground and provide the link here with you question.
+ 2
n = int(input())
#your code goes here
room=list(range(5,n,5))
for i in room:
print(i)
i+=1
+ 2
Don’t forget the colon after the for loop…. 🤦🏻
+ 1
n = int(input())
#your code goes here
for bathroom in range(5,n,5):
print (bathroom)
+ 1
n = int(input())
#your code goes here
for i in range(5, n, 5):
print(i)
+ 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)
+ 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
+ 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 :/
+ 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)
+ 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)?
+ 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
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)
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)
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!
- 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(_)