You are on page 1of 5

1)

n=1

while(n<6):

print('5 * ',n,'=',5*n)

n=n+1
2)

n=1

while(n<10):

print(n,end=',')

n=n+1

3)

n=1

while(n<10):

print(n,end=' ')

n=n+1

4) Write a python program to print the square of all numbers from 0 to 10

n=0
while(n<11):

print("Square of n",n*n)

n=n+1

5)Write a python program to find the sum of all even numbers from 0 to 10

n=2

c=0

while(n<11):

c=c+n

n=n+2

print("Sum of even num from 1 to 10 =",c)

6)Write a Python program to sum all the items in a list

total=0

list=[12,23,456,67]

for ele in range(0, len(list)):

total = total + list[ele]

print("SUM OF ALL ELEMENTS =",total)

7) Get the largest number from a list

list=[1,34,56,78,998,3456]

print("Largest number in the list is : ",max(list))

8) str1 = “this is a sample DaTaa”


 
Exercise : Check if ‘is’ present in str1

test_str = "this is a sample DaTaa"

if "is" in test_str :
print ("Yes, ‘is’ present in str1")

else :

print ("No, ‘is’ not present in str1")

9) Write a python program to design simple calculator performing arithmetic functions like addition, subtraction,
multiplication and division with the input given by user

def add(x, y):

return x + y

def subtract(x, y):

return x - y

def multiply(x, y):

return x * y

def divide(x, y):

return x / y

print("Select operation.")

print("1.Add")

print("2.Subtract")

print("3.Multiply")

print("4.Divide")

choice = input("Enter choice(1/2/3/4): ")

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

if choice == '1':

print(num1,"+",num2,"=", add(num1,num2))

elif choice == '2':

print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':

print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4':


print(num1,"/",num2,"=", divide(num1,num2))

else:

print("Invalid input")

10)Write a python program to find the sum of N natural numbers

i=0
s=0

n=int(input("Enter n value to find sum of natural numbers"))

while i<n:
s=s+i
i=i+1

print("Sum of",i," terms =",s)

11)Write the python program for the given operation in tuples

i)Maxima ii)minima iii)sum of two tuples iv) duplicate a tuple v)slicing operator vi) obtaining a list from a tuple vii)
Compare two tuples viii)printing two tuples of different data types

tup1,tup2=(24,432,122,23),(125,567,887,12)

print ("Max value element : ", max(tup1))

print ("Max value element : ", max(tup2))

print ("Adding two tuple : ", tup1+tup2)

tup3=tup2

print ("Duplicate od tuple2 into tuple3 :",tup3)

print("Using slicing operator ",tup1[1:3])

print("tuple1 into list",list(tup1))

print("Comparison of tuples")

if (tup1>tup2):
print("tup1 is bigger")

else:

print("tup2 is bigger")

print("Tuple with different data type")

tup4=("Appu",123,'apple',12.33)

print(tup4)

12)Python program to count even and odd numbers in a List

list=[2,3,5,77,8,85,876]

e=0

o=0

for num in list:

if num%2==0:

e=e+1

else:

o=o+1

print("Total number of odd numbers =",o)

print("Total number of even numbers =",e)

You might also like