CSE1001-Fall'20-Practice Problems 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CSE1001-Fall'20-Practice Problems 1 

1.

Water in a Dam
A city has a dam of capacity ‘x’ litres, water comes to the dam from ‘n’ places.  Given
the value of ‘n’ and the quantity of water (in litres and millilitres) that comes from ‘n’
places, Write an  algorithm and the corresponding Python code to determine the
total amount of water in the dam. Assume that the total quantity of water in the dam,
will be always less than the capacity of the dam. For example, if there are three places
from which water comes to the dam and the water from place 1 is 2 litres 500 ml,
water from second place is 3 litres 400 ml and water from third place is 1 litre 700 ml
then the total quantity of water in dam will be 7 litres 600 ml.

Input Format

Number of places from where water comes, n

Number of litres of water from place-1

Number of millilitres of water from place-1

Number of litres of water from place-2

Number of millilitres of water from place-2

...

Number of litres of water from plac- n

Number of millilitres of water from place- n

Output Format

Total litres of water in the dam

Total millilitres of water in the dam

2.

Digit Factors in a Number


Given a number ‘n’, design an algorithm and write the Python program to  print the
digits of ‘n’ that  divides ‘n’. Print the digits in reverse order of their appearance in
the number ‘n’.  For example, if n is 122 then print 2, 2, 1. Use only conditional and
iterative statements to write the code. If none of the digits divide the number, then
print ‘No factors’

Input Format

A number, n 

Output Format

Digits in the number ‘n’ that divides ‘n’ in reverse order

3.

Pattern
Given ‘n’, the number of rows, design an algorithm and write a Python code to draw
a pattern. If n is ‘5’, the pattern looks as shown below:

**

****

******

********

**********

4.

Roman Letters
The numeric system represented by Roman numerals originated in ancient Rome and
remained the usual way of writing numbers throughout Europe well into the late
Middle Ages. Numbers in this system are represented by combinations of letters as
shown below:

Roman
I VX L C D M
Numera
l
1 5 10 50 100
Value 15
0 0 0 0 0
 
Given a letter in Roman numeral, develop an algorithm and write the Python code to
print the value of it. If some other letter other than Roman numeral is given as input
then print ‘Enter a roman numeral’ and terminate.

Input Format

A Roman Letter

Output Format

Value equivalent to the letter

5.

CoPrime
Given two numbers ‘m’ and ‘n’, design an algorithm and write the Python code to
check if they are relatively prime. Two integers ‘a’ and ‘b’ are said to be relatively
prime, mutually prime, or coprime, if the only positive integer that divides both of
them is 1. For example, 14 and 15 are coprime since the factors of 14 are 1, 2, 7, & 14
and factors of 15 are 1, 3, 5, & 15 and there is no common factor other than 1. (Use
only conditional and iterational statements for designing the algorithm and
implementation).

Input Format

Number m

Number n

Output Format

Print either Coprime or Not coprime

You might also like