Python Forum
Arithmetic exercice with python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Arithmetic exercice with python (/thread-25773.html)



Arithmetic exercice with python - pythonuser1 - Apr-11-2020

Hello Guys,

I have an arithmetic exercice and I am stuck.

"Your program should read the number of students that can hold a room, then the number of students. Finally, it must display the number of rooms to reserve to hold all the students"

Example
entries :
5
29
output :
6

Here is my code : (nbEleveSalle will receive 5 and nbEleve will receive 29)
nbEleveSalle = int(input())
nbEleve = int(input())
résultat = (nbEleve//nbEleveSalle)+1
print(résultat)
The online plateform we use to validate our exercice, tells me this is not correct. Anyone have an idea please ? Thanks a lot


RE: Arithmetic exercice with python - Larz60+ - Apr-11-2020

Please post all code, output and errors (in it's entirety) between their respective tags. Refer to BBCode help topic on how. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Please, You need to start following the forum rules. You have been previously notified


RE: Arithmetic exercice with python - pythonuser1 - Apr-11-2020

Hello, sorry, I edited my code. The output only says your programm give 7 instead of 6.


RE: Arithmetic exercice with python - jefsummers - Apr-11-2020

You do have a problem. What if you enter 5 and 30? The correct answer would be 6, and your program gives 7.
Instead of adding 1, you should only add 1 if the they are not evenly divisible. Use the modulo operator as your test.


RE: Arithmetic exercice with python - pythonuser1 - Apr-11-2020

Thank you Jefsummers. You're right. It's working now.