Write a python program to create 4 divisions of a registered students

Write a python program to create 4 divisions of a registered students

Accept total no of participants in class.  A group of four divisions has to be created from registered participants . The limit for registration is 200 .

if total no of  participants registered is even number then , criteria for group division are that each group should have equal no of participants.

if total no of  participants registered is odd number then , criteria for group division are that take a nearest multiple of 4 less then n perform equal division then the left out participants are added in group D

Input

104  ---> n

Output:

26          no of participants in group A
26          no of participants in group B
26          no of participants in group C
26          no of participants in group D


Input

102  ---> n

Output:

25         no of participants in group A
25          no of participants in group B
25          no of participants in group C
27          no of participants in group D

Python Code:-

#get the input from the user of no of registered students

n=int(input())

a=0

b=0

c=0

d=0

#check if even no of students

if (n%2==0):

#Check if no of students divisible by 4

#if yes then divide them in equal groups

    if(n%4==0):

        a=int(n/4)

        b=int(n/4)

        c=int(n/4)

        d=int(n/4)

        print(a,b,c,d)

#if no of students are odd

else:

#store the remaining odd of students in x

    x=n%4

#substract the odd no of students from the no of students 

    n=n-x

#Check if no of students divisible by 4

    if(n%4==0):

#if yes then divide them in equal groups

        a=int(n/4)

        b=int(n/4)

        c=int(n/4)

        d=int(n/4)

#then add the remaining odd no of students i.e x into d group

    d=d+x

    print(a,b,c,d)

    Output:-







 Java Code: -

import java.util.*;

class divide

{

    public static void main(String[] args)

    {

        int a,b,c,d;

        Scanner sc=new Scanner(System.in);

        System.out.println();

        int n = sc.nextInt();

        if (n%2==0)

        {

            if(n%4==0){

                a=n/4;

                b=n/4;

                c=n/4;

                d=n/4;

                System.out.print(a); 

                System.out.print(" " +b); 

                System.out.print(" " +c); 

                System.out.print(" " +d); 

            }

        }

        else 

        {

            int x=n%4;

            n=n-x;

            if(n%4==0)

            {

                a=n/4;

                b=n/4;

                c=n/4;

                d=n/4;

                System.out.print(a); 

                System.out.print(" " +b); 

                System.out.print(" " +c); 

                System.out.print(" " +(d+x)); 

            }

            

        }

    }

}




Post a Comment

0 Comments