+ 4
Should it be marked wrong? Or is my logic broken?
I had this practice in the Python for beginners course (33.2): The code should take a number of floors in a building as input, and it should output the floors that have a bathroom, 1 every 5th floor. Eg. INPUT 23 OUTPUTS 5, 10, 15, 20. This is my code (marked correct, but…): https://code.sololearn.com/cX3Ry3Sich74/?ref=app But isn’t it wrong? “20” as input will not print 20. n+1 would solve the problem tho, it’s marked correct too. Should my 1st code be marked incorrect? Or am I wrong?
17 Answers
+ 4
Okay, makes sense, and they even mention the range bounds. Looks like they were just being easy and didn't provide test cases that would break it
+ 9
Hamsdino I think they just didn't consider input that are multiples of 5 in the test cases. :)
+ 5
I didn't "decide what to do", I asked to you have a look at the previous comments.
This way, you can find out that the OP has found a solution and the problem/ confusion is particularly about the sololearn test cases.
+ 3
Have a look at the range function: The upper bound is NOT INCLUDED: [lower; upper)
+ 2
Per Bratthammar Hello. My answer is already correct though. But I wonder WHY it’s correct.
+ 1
range is everything but not including the last. So if you input 20, the last number checked will be 19
When you take input, just add 1 to it
+ 1
You can let them know to stop future confusion, but i don't think that was the point of the excersize
+ 1
Rahmatova Gulnoza Please read the thread's description and the previous answers
0
Paste the problem details. It probably because thats what it asked for
0
Hamsdino
Hi! Try put your range from 1 to n + 1.
In the loop put a if statement with the condition that i modulo 5 will give no rest. Only print i when the if statement is true.
0
Slick
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.
0
Lisa
That must be the case :( they’re too nice with us, that got me confused. Thank you
0
Slick Yeah, probably. But since I always try to break it, it got me confused lol Do you think it was on purpose or should it be reported?
0
Slick Thank you!
- 1
Lisa! It's not up to you to decide what I do!