Unit 1 Programs For Tesselator
Unit 1 Programs For Tesselator
---------
Program 1:
---------
'''Write a program that asks the user to enter a distance in kilometers and then
prints out how far that distance is in miles.
Note: (conversion factor=0.621371)
Input format
----------------------------------------
Read the distance in km
Output format
-----------------------------------------
Print distance in miles
Sample Input:1
------------------------------------
4
Sample Output:1
-----------------------------------
2.485484
# conversion factor
conv_fac = 0.621371
# calculate miles
miles = kilometers * conv_fac
print(miles)
Test cases:
case=1
input=2.5
output=1.5534275
case=2
input=4
output=2.485484
case=3
input=1
output=0.621371
_______________________________________________________________________
Program 2:
'''Write a program to swap two numbers using bitwise operators
in python
Input format
----------------------------------------
Read two integer numbers
Output format
-----------------------------------------
swapping of two numbers
Sample Input:1
------------------------------------
40
60
Sample Output:1
-----------------------------------
60
40
x = int(input())
y = int(input())
print(x)
print(y)
Test cases:
case=1
input=50
10
output=10
50
case=2
input=5
10
output=10
5
case=3
input=7
8
output=8
7
______________________________________________________________________
Program 3:
----------
"""
One grandeur Trade Fair Event was organized by the Confederation of National Large
Scale Industry.
Number of people who attended the event on the first day was x. But as days
progressed,
the event gained good response and the number of people who attended the event on
the
second day was twice the number of people who attended on the first day.
Unfortunately
due to heavy rains on the third day, the number of people who attended the event
was
exactly half the number of people who attended on the first day.
Given the total number of people who have attended the event in the first 3 days,
find the number of people who have attended the event on day 1, day 2 and day 3.
"""
t=int(input("Enter the total number of people : "))
x=(2*t)//7
print("Number of attendees on day 1 :",x)
print("Number of attendees on day 2 :",2*x)
print("Number of attendees on day 3 :",x//2)
Test cases:
case=1
input=10500
output=
Enter the total number of people :
Number of attendees on day 1 : 3000
Number of attendees on day 2 : 6000
Number of attendees on day 3 : 1500
case=2
input=14000
output=
Enter the total number of people :
___________________________________________________________________________________
_
Program 4:
----------
Consider a currency system in which there are only six types of note denominations,
namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100.
If the amount to be given to Rahul is Rs. N. Find the minimum number of notes that
will
combine to form Rs. N.
N = int(input("Enter N: "))
S = N//100 + (N%100)//50 + (N%50)//10 + (N%10)//5 + (N%5)//2 + ((N%5)%2)//1
print("Minimum number of notes required:",S)
Test cases:
case=1
input=1200
output=
Enter N:
Minimum number of notes required: 12
case=2
input=242
output=
Enter N:
Minimum number of notes required: 7
case=3
input=368
output=
Enter N:
___________________________________________________________________________________
__
Program 5:
----------
"""
No. of tickets sold to adults are X more than the total tickets sold to child and
seniors.
Number of tickets sold to children is exactly half that of seniors tickets.
Assume that an adult ticket costs Rs. 50, children ticket costs Rs. 20 and
senior ticket costs Rs. 30. They will get Y Rupees from that show.
Find the number of adult tickets, children tickets, and senior tickets sold.
"""
X = int(input("Enter the value of X:"))
Y = int(input("Enter the value of Y:"))
Ch = (Y - 50*X)//230
print("Number of children tickets sold:",Ch)
print("Number of adult tickets sold:",3*Ch+X)
print("Number of senior tickets sold:",2*Ch)
Test cases:
case=1
input=10
5100
output=
Enter the value of X:
Enter the value of Y:
Number of children tickets sold: 20
Number of adult tickets sold: 70
Number of senior tickets sold: 40
case=2
input=5
2550
output=
Enter the value of X:
Enter the value of Y:
Number of children tickets sold: 10
Number of adult tickets sold: 35
Number of senior tickets sold: 20
___________________________________________________________________________________
__
Conditional
-----------
Program 1:
'''program to check whether the given integer is a multiple of both 5 and 7
Input format
----------------------------------------
Enter an integer
Output format
-----------------------------------------
is a multiple of both 5 and 7 or is not a multiple of both 5 and 7
Sample Input:1
------------------------------------
Enter an integer: 44
Sample Output:1
-----------------------------------
is not a multiple of both 5 and 7
Test cases:
case=1
input=12
output=Enter an integer:
12 is not a multiple of both 5 and 7
case=2
input=35
output=Enter an integer:
35 is a multiple of both 5 and 7
case=3
input=44
output=Enter an integer:
44 is not a multiple of both 5 and 7
__________________________________________________________________________
Program 2:
'''Read two numbers from the user, find the maximum.
Input format
----------------------------------------
Read two numbers
Output format
-----------------------------------------
Print max of two
Sample Input:1
------------------------------------
4
2
Sample Output:1
-----------------------------------
4
num1 = int(input())
num2 = int(input())
Test cases:
case=1
input= 12
34
output=34
case=2
input=4
12
output=12
case=3
input=-12
11
output=11
_______________________________________________________________________
Program 3:
"""
Write a Python program to input three angles of a triangle. If a Triangle can be
formed with given input, Check whether it forms a ‘right Triangle’ or
‘Equilateral Triangle’ or ‘Normal Triangle’. If Triangle cannot be formed,
display ‘Triangle can not be formed’.
Sample Input 1:
60
50
70
Sample Output 1:
Normal Triangle
Sample Input 2:
60
60
70
Sample Output 2:
Triangle can not be formed
Sample Input 3:
90
60
30
Sample Output 3:
Right Triangle
"""
a=int(input())
b=int(input())
c=int(input())
if(a+b+c==180):
if(a==90 or b==90 or c==90):
print('Right Triangle')
elif(a==60 and b==60):
print('Equilateral Triangle')
else:
print('Normal Triangle')
else:
print('Triangle can not be formed')
Test cases:
case=1
Input=60
50
70
output=
Normal Triangle
case=2
input=60
60
70
output=
Triangle can not be formed
case=3
input=90
60
30
output=
Right Triangle
case=4
input=60
60
60
output=
Equilateral Triangle
__________________________________________________________________________________
Program 4:
----------
"""
Jim has a new obsession: crazy numbers. A number is crazy if it is either a
multiple of 13
or if it is one more than a multiple of 13.
Write a Python program that takes an integer and prints Crazy if a number is crazy.
Examples
Input: 13
Output: Crazy
Input: 27
Output: Crazy
Input: 42
Output: Not Crazy
Input: -12
Output: Crazy
"""
num=int(input())
if num%13==0 or num%13==1:
print("Crazy")
else:
print("Not Crazy")
Test cases:
case=1
input=13
output=crazy
case=2
Input=27
Output=Crazy
case=3
Input=42
Output=Not Crazy
case=4
Input=-12
Output=Crazy
__________________________________________________________________________________
Program 5:
"""
Write a Python program to find roots of quadratic equation.
Take a,b,c values as input.
If a=0 print Invalid input else print the roots of given equation.
Sample 1:
Enter 'a' value: 1
Sample 2:
Enter 'a' value: 1
Sample 3:
Enter 'a' value: 0
Invalid input
Sample 4:
Enter 'a' value: 2
Test cases:
case=1
input=1
1
1
output=
Enter 'a' value:
case=2
input=1
2
1
output=
Enter 'a' value:
case=3
input=0
2
1
output=
Enter 'a' value:
Invalid input
case=4
input=2
9
3
output=
Enter 'a' value:
case=5
input=2
-3
9
output=
Enter 'a' value:
case=6
input=1
-6
9
output=
Enter 'a' value:
___________________________________________________________________________________
____
Iterative
---------
Program 1:
'''Write a program that prints the numbers from 1 to 'N'. But for multiples of
three print “Zing" instead of the number and for the multiples of five print
“Bing".
For numbers which are multiples of both three and five print “ZingBing“.
Input format:
----------------------------------
Read N value
Output format:
----------------------------------
print numbers upto N ,for multiples of 3 print Zing,
for multiples of 5 print Bing both three and five print “ZingBing“
Sample Input:1
----------------------------------
10
Sample Output:1
----------------------------------
1
2
Zing
4
Bing
Zing
7
8
Zing
Bing
n = int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("ZingBing")
elif i%5==0:
print("Bing")
elif i%3==0:
print("Zing")
else:
print(i)
Test cases:
case=1
input=15
output=1
2
Zing
4
Bing
Zing
7
8
Zing
Bing
11
Zing
13
14
ZingBing
case=2
input=10
output=1
2
Zing
4
Bing
Zing
7
8
Zing
Bing
case=3
input=6
output=1
2
Zing
4
Bing
Zing
_________________________________________________________________________
Program 2:
'''Write a program to print the sum of the digits of a given number. For example
if the input is 123, the result should be 1+2+3=6.
Input format:
----------------------------------
An integer value
Output format:
----------------------------------
sum of digits of a given number
Sample Input:1
----------------------------------
145
Sample Output:1
----------------------------------
10
Explanation:1+4+5=10'''
n = int(input())
s = 0
while n>0:
s = s+n%10
n=n//10
print(s)
Test cases:
case=1
input=123
output=6
case=2
input=23
output=5
case=3
input=71
output=8
_______________________________________________________________________
Program 3:
'''Read a number 'N' and print the multiplication table as given below.
Note: Use proper spaces in output.
Ex: 2 * 1 = 2 -----> 2<space>*<space>1=<space>2
Input format:
----------------------------------
A number N
Output format:
----------------------------------
Multiplication table of N upto 10
Sample Input:1
----------------------------------
2
Sample Output:1
----------------------------------
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20
'''
n = int(input())
for i in range(1,11):
print(n,"*",i,"=",n*i)
Test cases:
case=1
input=2
output=
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20
case=2
input=5
output=
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
______________________________________________________________________
Program 4:
'''Given a number 'N', Program to check if it can be written as the sum of
the first few prime numbers. Print ‘Yes’ if 'N' can be written as first few
prime numbers and ‘No’ otherwise.
For example,
if N is 5 then print ‘Yes’ as it can be written as 2+3,
if N is 41 then print ‘Yes’ as it can be written as 2 + 3 + 5 + 7 + 11 + 13
if N is 11 then print 'No'
Input format:
----------------------------------
Read N value
Output format:
----------------------------------
Yes or No(Boolean values)
Sample Input:1
----------------------------------
5
Sample Output:1
----------------------------------
Yes
Explanation:5 can be written as 2+3
Sample Input:1
----------------------------------
11
Sample Output:1
----------------------------------
No
'''
n = int(input())
s = 2
flag = False
for i in range(3,n):
for j in range(2,i):
if i%j==0:
break
else:
s = s+i
if s==n:
flag=True
break
if flag:
print("Yes")
else:
print("No")
Test cases:
case=1
input=5
output=Yes
case=2
input=6
output=No
case=3
input=-1
output=No
case=4
input=10
output=Yes
case=5
input=11
output=No
_________________________________________________________________________
Program 5:
'''
You have given N bricks.
You need to construct a staircase as follows:
1. =
2. ==
3. ===
4. ====
Where = indicates one brick.
Another condition is row-1 should have 1 brick, row-2 should have 2 bricks and so
on.
i.e., i-th row should have 'i' bricks.
Your task is to findout total number of staircases can be formed with the given
condition.
Input Format:
-------------
An integer N
Output Format:
--------------
Print an integers, number of staircases
Sample Input-1:
---------------
5
Sample Output-1:
----------------
2
Explanation:
------------
row-1: =
row-2: ==
row-3: ==
Only 2 rows satisfies the condition.
Sample Input-2:
---------------
8
Sample Output-2:
----------------
3
Explanation:
------------
row-1: =
row-2: ==
row-3: ===
row-4: ==
Test cases:
case=1
input=8
output=3
case=2
input=5
output=2
case=3
input=10
output=4
_______________________________________________________________________
Program 6:
'''
Mr Somanath is a math teacher. He gave a problem to his students.
The students are given a number N, and the student has to perform following step:
- Add each digit of the number and add the result to N
Repeat this procedure until N becomes a single digit number.
Your task is to help the students to perform the above steps and
print the resultant single digit number N.
Input Format:
-------------
An integer, number N.
Output Format:
--------------
Print an integer result.
Sample Input-1:
---------------
95
Sample Output-1:
----------------
5
Explanation:
------------
95 => 9 + 5 = 14
14 => 1 + 4 = 5
Answer is 5
Sample Input-2:
---------------
765
Sample Output-2:
----------------
9
'''
n = int(input())
s = n
while(s > 9):
s=0
while(n > 0):
s=s+n%10
n=n//10
n=s
print(s)
Test cases:
case=1
input=95
output=5
case=2
input=7894569
output=3
case=3
input=765
output=9
___________________________________________________________________________________
__________________
Built-in functions
------------------
Program 1:
"""
Write a python program to take a string from user then
1. filter all the vowels and
2. filter all the digits
"""
s = input("Enter a string: ").lower()
Test cases:
case=1
input=Python latest version is 3.10
output=
Enter a string:
['o', 'a', 'e', 'e', 'i', 'o', 'i']
['3', '1', '0']
case=2
input=welcome to kmit123.com
output=
Enter a string:
Program 2:
"""
Write a python program to find the prime numbers from
the given list of integers
5 9 6 7 12 19
"""
def isPrime(n):
for i in range(2,n):
if n%i==0:
return False
return True
print("Enter integer elements:")
lst = list(map(int,input().split()))
res = list(filter(isPrime, lst))
print("Resultant List:",res)
"""
Test cases:
case=1
input=5 9 6 7 12 19
output=
Enter integer elements:
case=2
input=85 31 24 91 29 71
output=
Enter integer elements:
"""