Python Forum
Arithmetic exercice with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arithmetic exercice with python
#1
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
Reply
#2
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
Reply
#3
Hello, sorry, I edited my code. The output only says your programm give 7 instead of 6.
Reply
#4
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.
Reply
#5
Thank you Jefsummers. You're right. It's working now.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Arithmetic and python pythonuser1 1 1,615 Apr-12-2020, 07:11 PM
Last Post: pythonuser1
  Arithmetic Application design Emoji 1 1,822 Jul-23-2019, 11:16 AM
Last Post: jefsummers
  Arithmetic operations using lists yassine 2 2,397 May-02-2018, 06:20 PM
Last Post: j.crater
  Beginner - help for an exercice greed13 1 3,118 Dec-08-2017, 02:09 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020