Python Forum
Arithmetic and python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arithmetic and python
#1
Hello Guys,

I have a issue with this problem :

nbEleveEcole : number of students in the school. First input
nbClasse : number of classes. Second input

Your program must determine a distribution of students in classes such that the enrollment of two separate classes differs by at most 1. It will display the enrollment of each of the classes, starting with the most heavily loaded classes.

Example
Input :
39
6

Output :
7
7
7
6
6
6

Here is my code :

nbEleveEcole = int(input())
nbClasse = int(input())

for i in range(nbClasse):
    if nbEleveEcole % nbClasse == 0:
        nbEleve = nbEleveEcole // nbClasse
        print(nbEleve)

    if nbEleveEcole % nbClasse != 0:
        nbEleve = nbEleveEcole // nbClasse
        reste = nbEleveEcole % nbClasse
        if reste != 0:
            nbEleve = nbEleve + 1
        reste = reste - 1
        print(nbEleve)
If I test with 36 and 6, my first if is working
./répartition_des_classes.py
36
6
6
6
6
6
6
6

If I test with 39 and 6, my second if does not work properly, I don't know why. It returns me 7 six time instead of 3 times.
./répartition_des_classes.py
39
6
7
7
7
7
7
7

Does anyone have an idea of the error please ?
Reply
#2
Hello, I found the answer. The problem is solved
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Arithmetic exercice with python pythonuser1 4 2,150 Apr-11-2020, 04:00 PM
Last Post: pythonuser1
  Arithmetic Application design Emoji 1 1,841 Jul-23-2019, 11:16 AM
Last Post: jefsummers
  Arithmetic operations using lists yassine 2 2,433 May-02-2018, 06:20 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

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