Screenshot 2023-08-27 at 4.00.34 PM
Screenshot 2023-08-27 at 4.00.34 PM
Screenshot 2023-08-27 at 4.00.34 PM
32
654
198 7
CODING:
OUTPUT:
Write a program to generate prime
1.
CODING:
num = 29
num = int(input("Enter a number: "))
flag = False
if num == 1:
print(num, "is not a prime number")
elif num > 1:
flag = True
break
if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")
OUTPUT:
~IDLEShell3.10.5
FileEditShellDebugOptionsWindowHelp
Python3.10.5(tags/v3.10.5:377153,Jun62022,16:14:13)[MSCv.192964bit(AMD64)]onwin32
Type"help","copyright","credits"or"license()"formoreinformation.
>>>
RESTART:C:/Users/Admin/AppData/Local/Programs/Python/Python310/02.py
Enteranumber:5
5isaprimenumber
>>>
CODING:
def character_frequency(string):
for i in string:
count = 0
print(i,":", count, end = ", ")
count += 1
return count
print(character_frequency(“helloworld“))
OUTPUT:
CODING:
string=raw_input("Enter string:")
vowels=0
for i in string:
if(i=='a' or i=='e' or i=='i' or i=='o' or
i=='u' or i=='A' or i=='E' or i=='I' or i=='O'
or i=='U'):
vowels=vowels+1
print("Number of vowels are:")
print(vowels)
OUTPUT:
CODING:
OUTPUT:
6.Write a python function that takes a
list of words and returns the length of the
longest one.
CODING:
def find_longest_word(words_list):
word_len = []
for n in words_list:
word_len.append((len(n), n))
word_len.sort()
return word_len[-1][0], word_len[-1][1]
result = find_longest_word(["PHP",
"Exercises","Backend"])
print("\nLongest word: ",result[1])
print("Length of the longest word: ",result[0])
OUTPUT:
7. WAP for bubble sort.
CODING:
def bubbleSort(arr):
n = len(arr)
swapped = False
for i in range(n-1):
for j in range(0, n-i-1):
if arr[j] > arr[j +
1]: swapped =
True
arr[j], arr[j + 1] = arr[j + 1],
arr[j] if not swapped:
return
OUTPUT:
sort.
CODING:
def insertionSort(arr):
if (n := len(arr)) <=
1: return
for i in range(1, n):
key = arr[i]
j = i-1
while j >=0 and key < arr[j] :
arr[j+1] =
arr[j] j -= 1
arr[j+1] = key
OUTPUT:
Rahul Descrip9on
Age 32
Height 175 cm
Weight 75kg
IQ 100
Aryan Descrip9on
Age 25
Height 165 cm
Weight 75kg
IQ 50
CODING:
def add_num(a,b):
sum=a+b;
return sum;
num1=32
num2=25
print("The addition of age
is",add_num(num1,num2))
def mul_Num(a,b):
multiply=a*b;
return multiply;
num1=100
num2=50
print("multiplication of IQ
is",mul_Num(num1,num2))
def div(a,b):
return a/b
print("Division of IQ:",div(100,50))
def subtraction(x,y):
sub=x-y
return sub num1=int(input("please
enter first number: "))
num2=int(input("please enter
second number: "))
print("Subtraction of heights is :
",subtraction(num1,num2))
OUTPUT:
Write definition of a method ZeroEnding(scores)
10.
to add all those values in the list of scores, which are ending
with zero(0) and display the sum.
For example,
If the scores contain [200, 456,300,100,234,678] The sum
should e displayed as 600
CODING:
def zero_ending(scores):
total = 0
for number in scores:
if number%10 ==
0:
total += number
return total
CODING:
def sumDigit(string):
sum = 0
for a in string:
#Checking if a character is digit and adding it
if(a.isdigit()):
sum += int(a)
return sum
userInput =( input("Enter any string with digits: "))
OUTPUT: