You are on page 1of 7

1, Write a python program to calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and circle.

print('''Enter number to select shape:


1 for triangle
2 for rectangle
3 for square
4 for circle ''')
n = int(input("Enter your choice 1,2,3,4 :"))
if (n==1):
S1 = int(input("Enter the length of Side 1 :"))
S2 = int(input("Enter the length of Base :" ))
S3 = int(input("Enter the length of Side 3 :"))
h = int(input("Enter the height of the triangle : "))
print ("Perimeter of trinagle is ",(S1+S2+S3))
print ("Area of triangle is ",(1/2*S2*h))
elif (n==2):
l = int(input("Enter the length of the rectangle : "))
b = int(input("Enter the base of the rectangle : "))
print("Perimeter of the rectangle is : ",(2*(l+b)))
print("Area of the rectangle is : ",(l*b))
elif(n==3):
s = int(input("Enter the length of the side of square : "))
print("Perimeter of square is ",(4*s))
print("Area of square is ",(s*s))
elif(n==4):
r = int(input("Enter the radius of the circle : "))
print("Circumference of the circle is ",(2*3.14*r))
print("Area of the circle is ",(3.14*r*r))
else:
print("Invalid Option")
2, Write a program to calculate Simple and Compound interest.

principal = float(input('Enter amount: '))


time = float(input('Enter time: '))
rate = float(input('Enter rate: '))

simple_interest = (principal*time*rate)/100
compound_interest = principal * ( (1+rate/100)**time - 1)

print('Simple interest is: %f' % (simple_interest))


print('Compound interest is: %f' %(compound_interest))

3, Write a python program to find average and grade for given marks.

sub1=int(input("Enter marks of the first subject: "))


sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")
4, Find the number of occurrences of a sequence in a NumPy array

import numpy

arr = numpy.array([[2, 8, 9, 4],


[9, 4, 9, 4],
[4, 5, 9, 7],
[2, 9, 4, 3]])

output = repr(arr).count("9, 4")

print(output)

5, Write a program to calculate tax – GST / Income Tax

selling_price = int(input("Enter selling price of the product:"))


gst_rate = 18
gst_price = selling_price * 18 / 100
net_price = selling_price + gst_price
print(f"GST applied rs: {gst_price} at GST rate{gst_rate}%")
print(f"Total cost of the product after applying GST {net_price}")

6, Write a program to print the words starting with a particular alphabet in a user-entered string
string = input("Enter a string: ")

alphabet = input("Enter an alphabet to search for: ")

words = string.split()

matching_words = [ ]

for word in words:


if word[0] == alphabet:
matching_words.append(word)

print("The words starting with the alphabet", alphabet, "are:", matching_words)

7, write a python program to print the following pattern

1
21
321
4321
54321

rows = 6
for i in range(1, rows):
for j in range(i, 0, -1):
print(j, end=' ')
print("")
8, write a python program to print the following pattern

1
32
654
10 9 8 7

start = 1
stop = 2
current_num = stop
for row in range(2, 6):
for col in range(start, stop):
current_num -= 1
print(current_num, end=' ')
print("")
start = stop
stop += row
current_num = stop

9, write a python program to print the following patterns

*
**
***
****
*****
******
******
*****
****
***
**
*

rows = 6
for i in range(0, rows):
for j in range(0, i + 1):
print("*", end=' ')
print(" ")

print(" ")

for i in range(rows + 1, 0, -1):


for j in range(0, i - 1):
print("*", end=' ')
print(" ")

10, write a python program to print the following pattern

*
**
***
****
*****
****
***
**
*

rows = 5
i=1
while i <= rows:
j=i
while j < rows:
# display space
print(' ', end=' ')
j += 1
k=1
while k <= i:
print('*', end=' ')
k += 1
print()
i += 1

i = rows
while i >= 1:
j=i
while j <= rows:
print(' ', end=' ')
j += 1
k=1
while k < i:
print('*', end=' ')
k += 1
print('')
i -= 1

You might also like