Python File
Python File
output
Program -2 Write a program to check whether a number is an Armstrong number or not
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
output
Program-3 Write a python program to that accepts length of three sides of a triangle as inputs.
The program should indicate whether or not the triangle is a right angled triangle (use
Pythagorean theorem).
print("Triangle Possible")
else :
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = 7
if num < 0:
elif num == 0:
output
program-5 Write a program to print the sum of all the primes between two ranges
code - lower_value = int(input ("Please, Enter the Lowest Range Value: "))
if number > 1:
if (number % i) == 0:
break
else:
print (number)
output-
program 6- Write a python program to construct the following pattern using nested for loop:
**
***
****
*****
print(str(i) * i)
output
string1 = input()
string2 = input()
temp = string1
string1 = string2
string2 = temp
print("\nString after swap:")
output--
program-7 Write a Program to Count the Occurrences of Each Word in a Given String Sentence
word = "am"
words = string.split()
count = 0
for w in words:
if w == word:
count += 1
print(count)
output
program -8 Write a program to create, concatenate and print a string and accessing substring
from a given string.
strOne = input()
strTwo = input()
program-9 Write a menu driven program to accept two strings from the user and perform the
various functions using user defined functions
program 10- Write a program to find smallest and largest number in a list
code lst = []
for n in range(num):
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is :",
min(lst))
output
Program 11 Write a Program to Remove the ith Occurrence of the Given Word in a List
Code a=[]
for x in range(0,n):
a.append(element)
print(a)
c=[]
count=0
for i in a:
if(i==b):
count=count+1
if(count!=n):
c.append(i)
else:
c.append(i)
if(count==0):
else:
output
program 12 Create a dictionary whose keys are month names and whose values are the number
of days in the corresponding months.
Ask the user to enter a month name and use the dictionary to tell them how many
Print out the key value pairs sorted by number of days in each month
(ii)
lst.sort()
print( lst )
(iii)
for i in month :
if month [ i ] == 31 :
print( i )
(iv)
month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july" : 31
, "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}
print("feb")
for i in month :
if month [ i ] == 30 :
print(i)
for i in month :
if month [ i ] == 31 :
print( i)
output
program 13 Make a list of first 10 letters of the alphabet, then use the slicing to do the following
operations:
Print the letter from any particular index to the end of the list
test_list = []
test_list = list(string.ascii_uppercase)
output
program 14 – Write a program that scans an email address and forms a tuple of user name and
domain.
res = test_str[test_str.index('@') + 1 : ]
# printing result
output
program -15 Write a program that uses a user defined function that accepts name and gender (as
M for Male, F for Female) and prefixes Mr./Ms. on the basis of the gender.
Code
def prefix(name,gender):
print("Hello, Mr.",name)
print("Hello, Ms.",name)
else:
gender = input("Enter your gender: M for Male, and F for Female: ")
prefix(name,gender)
output