"Enter The Number Which You Print Table:" " " " "

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

 

                                                                    PRATICAL-4

 Programs to implement Control Statements(if, if-else, nested if-else, for loop, while loop, break
statement, continue statement): 

1. Display table of number using for-loop statement.


table=int(input("enter the number which you print table:"))
for x in range(1,11):
print(table,"*",x,"=",table*x)

C:\Users\a\Desktop\18bcs4328\venv\Scripts\python.exe
C:/Users/a/Desktop/18bcs4328/program1.py

enter the number which you print table:6

6*1=6

6 * 2 = 12

6 * 3 = 18

6 * 4 = 24

6 * 5 = 30

6 * 6 = 36

6 * 7 = 42

6 * 8 = 48

6 * 9 = 54
6 * 10 = 60

2. Find sum of Natural numbers from 1 to 10. Add digits of a number using while loop.
sum = 0
for x in range(1,11):
sum =sum+x
print("sum of natural number 1 to 10 :",sum)
d=0
while sum>0:
r=sum%10
d=sum+r
sum=int(sum/10)
print("sum",d)

C:\Users\a\Desktop\18bcs4328\venv\Scripts\python.exe C:/Users/a/Desktop/18bcs4328/program1.py
sum of natural number 1 to 10 : 55
sum 10
                                                                       PRATICAL-5
 Write a program to Calculate area of the circles using followings Types of the functions 
1.Simple Function
def circle():
r=int(input("enter  radius of circle:"))
area=3.14*r*r
print(" area of circle :",area)
circle()

C:\Users\a\Desktop\18bcs4328\venv\Scripts\python.exe
C:/Users/a/Desktop/18bcs4328/program1.py

enter radius of circle:5


area of circle : 78.5
2. Parameterized Functions 
def circle(r):
a=3.14*r*r
print(" area of circle :",a)
circle(8)

C:\Users\a\Desktop\18bcs4328\venv\Scripts\python.exe
C:/Users/a/Desktop/18bcs4328/program1.py
area of circle : 200.96
3. Functions with return type
 
def circle():
r=int(input("enter the radius:"))
area=3.14*r*r
return area
f=circle()
print("the area is:",f)

C:\Users\a\Desktop\18bcs4328\venv\Scripts\python.exe
C:/Users/a/Desktop/18bcs4328/program1.py

enter the radius:5


the area is: 78.5
4. Function with Return type with parameters
def circle(r):
area=3.14*r*r
return area
a=circle(12)
print("the area is:",a)

C:\Users\a\Desktop\18bcs4328\venv\Scripts\python.exe
C:/Users/a/Desktop/18bcs4328/program1.py
the area is: 452.15999999999997
                       
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                          PRATICAL-6
 
Write a program to calculate factorial of 10 numbers using return type with
function. Using Single functions Only
def factorial(a):
for x in range(1,a):
  a = a*x
return a
for x in range (1,11):
number=int(input("enter the no:"))
print(factorial(number))
 

C:\Users\a\Desktop\18bcs4328\venv\Scripts\python.exe
C:/Users/a/Desktop/18bcs4328/program1.py

enter the no:5

120

enter the no:4

24

enter the no:3

enter the no:2

enter the no:1


1

enter the no:8

40320

enter the no:9

362880

enter the no:12


479001600
 
 

You might also like