final
final
a=int(input("Enter a number:"))
for i in range(2,21):
print(a,"X",i,"=",a*i)
OUTPUT
Enter a no.2
Table of 2:
2x1=1
2x2=4
2x3=6
2x4=8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9= 18
2 x 10 = 20
2.WAP to input a No. & check is it Prime No. or not.
num = int (input ("Enter a number: "))
prime = 1
for i in range (2, num) :
if num & i == 0:
prime = 0
if prime and num › 1:
print (num, "is a prime number.")
else:
print (num, "is not a prime number.")
OUTPUT
Enter a number: 27
27is a prime number.
3.WAP to input two Nos. & print the counting
between them
startnum = int (input ("Enter the starting number:
"))
endnum = int (input ("Enter the ending number: "))
print("Counting between", start_num, "and", end_
_num, " : ") for num in range (start_num + 1,
end_num) :
print(num, end=' ,')
OUTPUT
Enter the starting number: 1
Enter the ending number: 40
Counting between 1 and 40:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,2
1,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,
38,39,40
4.WAP to input Marks of any five subjects & print its
total and average.
total _marks = 0
for i in range (1, 6) :
marks = int/(input ("Enter marks for Subject:"))
total marks += marks
average_marks = total_marks / 5
print ("Total Marks:", total_marks) print ("Average
Marks:", average_marks)
OUTPUT
Enter marks for Subject1:19
Enter marks for Subject2:20
Enter marks for Subject3:18
Enter marks for Subject4:20
Enter marks for Subject5:16
Total Marks: 93
Average Marks: 18.6
5.WAP to print the sum of first 20 Even Nos.
sum=0
for i in range(21 42, 2) :
sum=sum+i
print ("Sum of the first 20 even numbers:", sum)
OUTPUT
Sum of the first 20 even numbers: 420
6.WAP to print the product of first 5 Natural Nos.
product=1
for i in range (1, 6) :
product = product * i
print ("The product of first 5 Natural Nos.
is:",product)
OUTPUT
The product of first 5 Natural Nos. is: 120
7. WAP TO INPUT A NUMBER AND PRINT THE SUM
OF ITS ALL FACTORS.
n=int(input("enter a number:"))
sum=0
for i in range (1,n+1):
if n%i==0:
sum=sum+i
print('sum is',sum)
OUTPUT:
enter a number:10
sum is 18
8.WAP TO FIND THE SUM OF ALL ELEMENTS OF A
LIST.
L=[20,50,70,60]
sum=0
for i in L:
sum=sum+i
print("sum of list elements is",sum)
OUTPUT
sum of list elements is 200
9.WAP TO INPUT A STRING AND COUNT HOW MANY
SPACES ARE IN IT.
a=input("enter a string:")
count=0
for i in a:
if i ==" ":
count=count+1
print("number of spaces are",count)
OUTPUT
enter a string:aanya seth
number of spaces are 1
10.WAP TO define a list and do the following
operations on it: 1.append 2.insert 3.sort 4.reverse
5.polist=[1,3,4,2,5]
list.append(8)
list.insert(1,60)
list.sort()
list.reverse()
list.pop()
print("final list is",list)
OUTPUT:
final list is [60, 8, 5, 4, 3, 2]