+ 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?

14th Jul 2022, 7:11 PM
Hamsdino
Hamsdino - avatar
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
14th Jul 2022, 7:47 PM
Slick
Slick - avatar
+ 9
Hamsdino I think they just didn't consider input that are multiples of 5 in the test cases. :)
14th Jul 2022, 7:46 PM
Lisa
Lisa - avatar
+ 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.
17th Jul 2022, 12:31 PM
Lisa
Lisa - avatar
14th Jul 2022, 8:49 PM
Simon Sauter
Simon Sauter - avatar
+ 3
Have a look at the range function: The upper bound is NOT INCLUDED: [lower; upper)
14th Jul 2022, 7:35 PM
Lisa
Lisa - avatar
+ 2
Per Bratthammar Hello. My answer is already correct though. But I wonder WHY it’s correct.
14th Jul 2022, 7:47 PM
Hamsdino
Hamsdino - avatar
+ 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
14th Jul 2022, 7:33 PM
Slick
Slick - avatar
+ 1
Slick and Lisa I know that, but why is it marked correct too when I dont add +1 to the input? That’s what I’m curious about.
14th Jul 2022, 7:39 PM
Hamsdino
Hamsdino - avatar
+ 1
You can let them know to stop future confusion, but i don't think that was the point of the excersize
14th Jul 2022, 7:55 PM
Slick
Slick - avatar
+ 1
Rahmatova Gulnoza Please read the thread's description and the previous answers
17th Jul 2022, 12:12 PM
Lisa
Lisa - avatar
0
Paste the problem details. It probably because thats what it asked for
14th Jul 2022, 7:41 PM
Slick
Slick - avatar
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.
14th Jul 2022, 7:42 PM
Per Bratthammar
Per Bratthammar - avatar
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.
14th Jul 2022, 7:44 PM
Hamsdino
Hamsdino - avatar
0
Lisa That must be the case :( they’re too nice with us, that got me confused. Thank you
14th Jul 2022, 7:51 PM
Hamsdino
Hamsdino - avatar
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?
14th Jul 2022, 7:53 PM
Hamsdino
Hamsdino - avatar
0
Slick Thank you!
14th Jul 2022, 7:56 PM
Hamsdino
Hamsdino - avatar
- 1
Lisa! It's not up to you to decide what I do!
17th Jul 2022, 12:21 PM
Rahmatova Gulnoza
Rahmatova Gulnoza - avatar