0% found this document useful (0 votes)
6 views11 pages

Computer Project

Uploaded by

HC World
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Computer Project

Uploaded by

HC World
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

Write a program to print a series of 1 to 20 in


ascending and descending order using for and
while loops.

Ascending for loop

Syntax:
for i in range (1,21):
print(i)

Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Descending for loop

Syntax:

for i in range (21,0, -1):


print(i)

Output:

21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
Ascending while loop

Syntax:
i=1
while(i<21):
print (i)
i = i+1

Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Descending while loop
Syntax:
i=21
while(i>0):
print (i)
i = i-1

Output:
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
2. Write the program code for the following:
A.To print a table of a number using a while loop.
B.To print the sum of all the odd numbers in the
range entered by the user.
C.Write a Python code for generating the area of the
following geometrical figures:
a) Circle
b) Rectangle
c) Triangle
d) Square
e) Cube

a) To print a table of a number using a while


loop.
Syntax:
n = int(input('Enter the number for multiplication table:'))
i=1
while(i<=10):
print(n*i)
i = i+1

Output:
Enter the number for multiplication table:7
7
14
21
28
35
42
49
56
63
70
b) To print the sum of all the odd numbers in the range
entered by the user
Syntax:
n = int(input('Enter the range for the sum of odd
numbers:'))
for n in range(1, n+1):
if(n%2!=0):
print(n)

Output:
Enter the range for the sum of odd numbers:50
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
C)Write a Python code for generating the area of the
following geometrical figures:
a) Circle
b) Rectangle
c) Triangle
d) Square
e) Cube

a) Circle
Syntax:
radius = float(input(“Enter the radius of the circle:”))
Area = 3.14*radius*radius
Print(“Area of Circle is”, Area)

Output:
Enter the radius of the circle:2
Area of circle is 12.56
Rectangle
Syntax:
length = float(input("Enter the length of the Rectangle:"))
breadth = float(input("Enter the breadth of the Rectangle:"))
Area = length*breadth
print("Area of rectangle is",Area)

Output:
Enter the length of the Rectangle:5
Enter the breadth of the Rectangle:2
Area of rectangle is 10.0
Triangle
Syntax:
breadth = float(input("Enter the breadth of the triangle:"))
height = float(input("Enter the height of the triangle:"))
Area = 1/2*breadth*height
print("Area of triangle is",Area)

Output:
Enter the breadth of the Rectangle:5
Enter the height of the Rectangle:6
Area of rectangle is 15.0
Square
Syntax:
side = float(input('Enter the side of Square:'))
Area = side*side
print("Area of Square is",Area)

Output:
Enter the side of Square:4
Area of Square is 16.0
Cube
Syntax:
side = float(input('Enter the side of cube:'))
Area = 6*side*side
print("Area of cube is",Area)

Output:
Enter the side of cube:2
Area of cube is 24.0

You might also like