Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python how to count group size if there is remainder

"If the division does not go evenly, there may be fewer students in one group, but all others must have the desired number."

x = float(input("How many students"))
y = float(input("What is the group size?"))

division = (x / y)
remainder = (x % y)


print(f"Group size: ")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can do it like this:-

import math 
x = float(input("How many students"))
y = float(input("What is the group size?"))

division = (x / y)
remainder = (x % y)
if remainder == 0:
    print(f" No of Groups: {division}")
else:
    print("No of Groups:", math.ceil(division))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading