You are on page 1of 2

Python book examples: -----

1. Write a program in python to print the numbers from 1 to 10.


2. Write a program in python to print the following series:
1 3 5 7 9 11….
3. Write a program in python to display the vales from 10 to 1.

10 9 8 7 6 5 4 3 2 1

4. Write a program in python to print all natural numbers from 21 to 30.


5. Write a program in python to display the following series:

2 4 6 8 10 12 14 16 18 20.

6. Write a program in python to display the following series which is separated from coma(,):

2, 4, 6 , 8 , 10, 12, 14 , 16, 18, 20.

Python question
Q1. Program to find the sum of the natural number from 21 to 30 .
sum=0
for x in range(21,31):
sum=sum+x
print("sum=",sum)

Q2. Program to find the sum of the natural number from m to n, where m and n are input by user.
sum=0
n=int(input("enter starting value"))
m=int(input("enter ending value"))
for x in range(n,m+1):
sum=sum+x
print("sum=",sum)

Q3. Program to find the sum of even numbers from m to n, where m and n are input by user.
Sm=0
n=int(input("enter starting value"))
m=int(input("enter ending value"))
for x in range(n,m+1):
if(x%2==0):
sum=sum+x
print("even number=",sum)

Q4. Program to display multiplication table of a number entered by the user p to 10 times.
number = int(input ("Enter the number"))
#print ("The Multiplication Table ", number)
for i in range(1, 11):
print (number, 'x', i, '=', number * i)
Q5. Program to display multiplication table of m ,up to n times where number m and n are entered
by user.
m= int(input ("Enter the number"))
n= int(input ("number of times."))
print ("The Multiplication Table ", number)
for i in range(1, n):
print (m, 'x', i, '=', m * i)

Q6. Program to input a salary of an employee and display the salary that the person will receive for
each of next 5 years if he gets an increment of 10% every year.
Salary=int(input(“enter salary yearly”))
Inc=input(“write yes or no ”)
for x in range(1,6,1)
if(inc==”yes”):
salary=salary + salary*10/100
print(“salary is :”,salary)

Q7program to input the Principal, rate of Interest and display the simple interest to be paid at the
end of each year for n years.
p = float(input("principal? "))
rate = float(input("rate? "))
t = int(input("Number of years? "))
i = 0
for x in range(1, t+1,1):
si=(p*rate*t)/100
print(“si is :”,si)

Q8. Program to display the sum of factors of n which is input by user.


n=int(input("Enter a number: "))
s=0
for i in range(1,n+1):
if n%i==0:
s+=i
print("Sum of factors: ",s)

Q9. Program to display the sum of even factors of number input by the user.
n=int(input("Enter a number: "))
s=0
for i in range(1,n+1):
if n%i==0:
if i%2==0:
print(i)
s+=i
print("Sum of factors: ",s)

You might also like