PROGRAM TO PRINT THE NUMBER OF CHOCOLATES REMAINING:
STATEMENT:
Drek distributes C chocolates to school N students every Friday. The C chocolates are distributed among N students equally and the remaining chocolates R are given back to Drek.
As an example if C=100 and N=40, each student receives 2 chocolates and the balance 100-40*2 = 20 is given back.
If C=205 and N=20, then each student receives 10 chocolates and the balance 205-20*10 = 5 is given back.
Help the school to calculate the chocolates to be given back when C and N are passed as input.
PROGRAM:
C = int(input())
N = int(input())
print (C%N)
Input:
300
45
Output:
30
PROGRAM TO PRINT SUM OF EVEN NUMBERS FROM M TO N:
STATEMENT:
Two numbers M and N are passed as the input. The program must print the sum of even numbers from M to N (inclusive of M and N).
PROGRAM;
M = int(input())
N = int(input())
evensum = 0
for num in range(M,N+1):
if num%2 == 0:
evensum+=num
print (evensum)
Input:
2
11
Output:
30
Explanation:
The even numbers from 2 to 11 are 2 4 6 8 10
Their sum is 30.
No comments:
Post a Comment