Program 1 :
Write a program to calculate compound
interest when principal, rate and number of
periods are given.
# Python program to compute compound
interest
p = int(input(" Enter the principal amount :
"))
t = float(input(" Enter the time in years : " ))
r = float(input(" Enter the rate of interest : "))
# compute compound interest
amount = p * (pow((1 + r / 100), t))
ci = amount - p
# print
print(" Compound Interest : " , ci )
Program 2:
Read the name, address, email and phone
number of a person through the keyboard
and print the details.
Name = input("Enter Person Name : ")
Address = input("Enter Person Address : ")
Email = input("Enter Person Email : ")
Phone_no = int(input("Enter Phone number :
"))
print(" Please Confirm your provided
Information\n " )
print(" Person Name : " ,Name )
print(" Person Address : " , Address )
print(" Person Email : " , Email )
print(" Person Phone_no : " , Phone_no )
Program 3:
Print the below triangle using for loop.
5
44
333
2222
11111
n=int(input(“enter the no: of rows”))
for i in range(n, 0, -1):
for j in range(n - i):
print(i, end=" ")
print()
Program 4:
Write a program to check whether the given
input is digit or lowercase character or
uppercase character or a special
character(use 'if-else-if' ladder)
ch = input("Enter a character: ")
if [Link]():
print("It is a Digit")
elif [Link]():
print("It is a Lowercase character")
elif [Link]():
print("It is an Uppercase character")
else:
print("It is a Special character")
Program 5:
Python program to print all prime numbers in
a given interval (use break)
start = int(input("Enter start of interval: "))
end = int(input("Enter end of interval: "))
for num in range(start, end + 1):
if num > 1:
for i in range(2, num):
if num % i == 0:
break
else:
print(num)
Program 6:
Write a program to convert a list and tuple
into arrays.
import numpy as np
list = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ]
print ( " List to array: " )
array_1 = np . asarray ( list )
print ( type ( array_1 ) )
print ( array_1 )
print ( )
print ( )
tuple = ( [ 8, 4 , 6 ] , [ 1 , 2 , 3 ] )
print ( " Tuple to array: " )
array_2 = np . asarray ( tuple )
print ( type ( array_2 ) )
print ( array_2 )
Program 7:
Write a program to find common values
between two arrays.
import numpy as np
array1 = np . array ( [ 5, 10 , 20 , 40 , 60 ] )
print ( " Array1 : " , array1 )
array2 = np . array ( [10 , 30 , 40 ] )
print ( " Array2 : " , array2 )
print ( " Common values between two arrays
are : " )
print ( np . intersect1d ( array1 , array2 ) )
Program 8:
Write a function called palindrome that takes
a string argument and returns True if it is a
palindrome and False otherwise. Remember
that you can use the built-in function len to
check the length of a string.
def isPalindrome(s):
if (s == s[::-1]):
return True
else:
return False
s = 'radar'
result = isPalindrome(s)
if(result):
print(s, 'is a Palindrome.')
else:
print(s, 'is not a Palindrome.')
Program 9:
Write a function called is_sorted that takes a
list as a parameter and returns True if the list
is sorted in ascending order and False
otherwise.
def is_sorted(lst):
for i in range(len(lst) - 1):
if lst[i] > lst[i + 1]:
return False
return True
#It returns true if the elements are sorted
otherwise it returns false
numbers = [1, 2, 3, 4, 5]
print(is_sorted(numbers))
numbers = [5, 3, 1]
print(is_sorted(numbers))
Program 10:
Write a function called has_duplicates that
takes a list and returns True if there is any
element that appears more than once. It
should not modify the original list.
def has_duplicates(lst):
if len(lst) != len(set(lst)):
return True
else:
return False
numbers = [1, 2, 3, 4, 5]
print(has_duplicates(numbers))
numbers = [1, 2, 3, 2, 5]
print(has_duplicates(numbers))
Program 11:
Write a function called remove_duplicates
that takes a list and returns a new list with
only the unique elements from the original.
Hint: they don’t have to be in the same order.
def remove_duplicates(lst):
unique_list = []
for item in lst:
if item not in unique_list:
unique_list.append(item)
return unique_list
numbers = [10, 20, 20, 30, 40, 40, 50]
print(“The contents of a list after removing
duplicates elements
are :”,remove_duplicates(numbers))