Computer Science Practical Programs
Computer Science Practical Programs
SCIENCE
PRACTICAL FILE
|Atharv Jain |
|Roll no. 11 |
|XI-B |
SEQUENCE
SOURCE CODE
print("Hello")
OUTPUT:
Hello
------------------------------------------------------------------------------------------------------------
Q2. Write program to display your Name, Age, Address and Contact Number on
screen.
SOURCE CODE
N= "Atharv Jain"
A= "16"
AD= "A2251,Green Field Colony"
C= "9311599366"
print("Name= ",N)
print("Age= ",A)
print("Address= ",AD)
print("Contact Number= ",C)
OUTPUT:
SOURCE CODE
P="2"
PAGE 1
L="6"
D="2"
print("Program= ",P)
print("Logic= ",L)
OUTPUT:
Program= 2
Logic= 6
Documentation= 2
------------------------------------------------------------------------------------------------------------
SOURCE CODE
print("Name \t Marks")
print("Raj \t 76.5 \n Geeta \t 85.5 \n Simmy \t 93.5")
OUTPUT:
Name Marks
Raj 76.5
Geeta 85.5
Simmy 93.5
------------------------------------------------------------------------------------------------------------
SOURCE CODE
OUTPUT:
Enter first number= 2
Enter second number= 3
Sum of the two numbers= 5
------------------------------------------------------------------------------------------------------------
PAGE 2
[Link] a program to find and display total, average and product of 3 numbers
entered by user.
OUTPUT:
SOURCE CODE
OUTPUT:
Q8. Write a program to find and display Simple Interest and Compound Interest.
PAGE 3
Simple Interest = (Principle * Rate of Interest * Time Period) / 100
Compound Interest = ((Principle * (1 + Rate of Interest) /100) Time Period) –
Principle Amount
SOURCE CODE
OUTPUT:
Enter principal amount= 8925
Enter rate of interest= 9
Enter time period= 5
Simple Interest= 4016.25
Compound Interest= -4462.5
------------------------------------------------------------------------------------------------------------
SOURCE CODE
OUTPUT:
Enter length= 5
Enter breadth= 2
PAGE 4
Area of rectangle= 10
Perimeter of rectangle= 14
Diagonal of rectangle= 29
------------------------------------------------------------------------------------------------------------
SOURCE CODE
OUTPUT:
Enter radius= 5
Circumference= 31.400000000000002
Area= 78.5
Diameter= 10
------------------------------------------------------------------------------------------------------------
[Link] a program to find and display area of a Scalene Triangle, using Heron
Formula.
S = (side 1 + Side 2 + Side 3)/2
Area = square root of (s(s – side 1)*(s-side 2) * (s – side 3))
SOURCE CODE
OUTPUT:
PAGE 5
Enter first side= 6
Enter second side= 5
Enter third side= 4
Area of triangle= 9.921567416492215
------------------------------------------------------------------------------------------------------------
[Link] a program to input time in seconds and then convert it into Hours,
Minutes and Seconds.
SOURCE CODE
OUTPUT:
Enter time in seconds= 3600
Time in minutes= 60.0
Time in hours= 1.0
------------------------------------------------------------------------------------------------------------
[Link] a program to input money in Rupees and then convert it into paise,
dollars and pounds
SOURCE CODE
OUTPUT:
Enter money in rupees= 8000
Money in paise= 800000
Money in dollars= 100.0
Money in pounds= 80.0
------------------------------------------------------------------------------------------------------------
PAGE 6
[Link] a program to input two integers, interchange their values and then
display new values.
SOURCE CODE
OUTPUT:
SOURCE CODE
PAGE 7
percentage = (total / 125) * 100
print("Roll No:", roll_no)
print("Name:", name)
print("Total Marks =", total)
print("Percentage =", percentage, "%")
if total<125:
print(percentage)
else:
print("Wrong marks inputted")
SOURCE CODE
OUTPUT:
Enter initial velocity (u): 5
Enter acceleration (a): 4
Enter time (t): 5
Final velocity = 25.0 m/s
------------------------------------------------------------------------------------------------------------
[Link] a program to find energy = m * g * h
SOURCE CODE
PAGE 8
energy = m * g * h
print("Energy =", energy)
OUTPUT:
Enter mass (m): 10
Enter height (h): 10
Energy = 980.0
------------------------------------------------------------------------------------------------------------
[Link] a program to find distance = u * t + ½ at2
SOURCE CODE
PAGE 9
OUTPUT:
Enter number of days: 1097
3 Years 0 Months 2 Days
------------------------------------------------------------------------------------------------------------
[Link] a program to input temperature in Fahrenheit and the convert it to
Celsius. (C = F – 32/1.8)
SOURCE CODE
PAGE 10
[Link] a program to input a number and then find it is a 2-digit number or not?
SOURCE CODE
PAGE 11
OUTPUT:
Enter a number: 63
Multiple of both 7 and 9
------------------------------------------------------------------------------------------------------------
[Link] a program to input 2 different integers and then find and display the
bigger number.
SOURCE CODE
PAGE 12
OUTPUT:
Enter a number: 289
Ten’s place digit is 8
------------------------------------------------------------------------------------------------------------
[Link] a program to input 3 different Numbers and then find as well as display
the biggest number.
SOURCE CODE
if not passed:
PAGE 13
grade = "F"
else:
if 91 <= percentage <= 100:
grade = "A"
elif 81 <= percentage <= 90:
grade = "B"
elif 71 <= percentage <= 80:
grade = "C"
elif 61 <= percentage <= 70:
grade = "D"
elif 51 <= percentage <= 60:
grade = "E"
else:
grade = "F"
Roll No: 11
Name: Atharv Jain
Total Marks: 111.0
Percentage: 88.8
Result: PASS
Grade: B
------------------------------------------------------------------------------------------------------------
[Link] a program to enter Day Number and then display Day Name.
SOURCE CODE
PAGE 14
else:
print("Invalid day number")
OUTPUT:
Enter day number (1-7): 6
Day: Saturday
------------------------------------------------------------------------------------------------------------
Q13. Write a program to enter Month Number and then display Month Name.
SOURCE CODE
PAGE 15
import math
while True:
print("\nRECTANGLE OPERATIONS")
print("1. AREA")
print("2. PERIMETER")
print("3. DIAGONAL")
print("4. EXIT")
choice = int(input("Enter choice: "))
if choice == 4:
break
length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
if choice == 1:
print("Area =", length * breadth)
elif choice == 2:
print("Perimeter =", 2 * (length + breadth))
elif choice == 3:
print("Diagonal =", [Link](length**2 + breadth**2))
else:
print("Invalid choice")
OUTPUT:
RECTANGLE OPERATIONS
1. AREA
2. PERIMETER
3. DIAGONAL
4. EXIT
Enter choice: 3
Enter length: 5
Enter breadth: 2
Diagonal = 5.385164807134504
------------------------------------------------------------------------------------------------------------
[Link] a program to create a menu to do the following operations on a circle –
CIRCLE OPERATIONS
1. AREA
2. CIRCUMFERENCE
3. DIAMETER
4. EXIT
SOURCE CODE
import math
while True:
print("\nCIRCLE OPERATIONS")
print("1. AREA")
print("2. CIRCUMFERENCE")
print("3. DIAMETER")
PAGE 16
print("4. EXIT")
choice = int(input("Enter choice: "))
if choice == 4:
break
r = float(input("Enter radius: "))
if choice == 1:
print("Area =", [Link] * r * r)
elif choice == 2:
print("Circumference =", 2 * [Link] * r)
elif choice == 3:
print("Diameter =", 2 * r)
else:
print("Invalid choice")
OUTPUT:
CIRCLE OPERATIONS
1. AREA
2. CIRCUMFERENCE
3. DIAMETER
4. EXIT
Enter choice: 2
Enter radius: 5
Circumference = 31.41592653589793
------------------------------------------------------------------------------------------------------------
Q17. Write a program to create a menu to do the following operations on a Square –
SQUARE OPERATIONS
1. AREA
2. PERIMETER
3. EXIT
SOURCE CODE
while True:
print("\nSQUARE OPERATIONS")
print("1. AREA")
print("2. PERIMETER")
print("3. EXIT")
choice = int(input("Enter choice: "))
if choice == 3:
break
side = float(input("Enter side: "))
if choice == 1:
print("Area =", side * side)
elif choice == 2:
print("Perimeter =", 4 * side)
else:
print("Invalid choice")
PAGE 17
OUTPUT:
SQUARE OPERATIONS
1. AREA
2. PERIMETER
3. EXIT
Enter choice: 2
Enter side: 3
Perimeter = 12.0
------------------------------------------------------------------------------------------------------------
[Link] a program to create a menu to do the following operations on two
numbers entered by user –
ARITHMETIC OPERATIONS
1. SUM
2. DIFFERENCE
3. PRODUCT
4. QUOTIENT
5. REMAINDER
6. EXIT
SOURCE CODE
while True:
print("\nARITHMETIC OPERATIONS")
print("1. SUM")
print("2. DIFFERENCE")
print("3. PRODUCT")
print("4. QUOTIENT")
print("5. REMAINDER")
print("6. EXIT")
choice = int(input("Enter choice: "))
if choice == 6:
break
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
if choice == 1:
print("Sum =", a + b)
elif choice == 2:
print("Difference =", a - b)
elif choice == 3:
print("Product =", a * b)
elif choice == 4:
print("Quotient =", a / b)
elif choice == 5:
print("Remainder =", a % b)
else:
print("Invalid choice")
PAGE 18
OUTPUT:
ARITHMETIC OPERATIONS
1. SUM
2. DIFFERENCE
3. PRODUCT
4. QUOTIENT
5. REMAINDER
6. EXIT
Enter choice: 3
Enter first number: 1
Enter second number: 2
Product = 2.0
------------------------------------------------------------------------------------------------------------
Q19. Write a program to generate electricity bill by inputting Consumer No, Name,
Address, Meter Type
(Commercial or Domestic) and units consumed. Find and display the bill by the
following criteria –
SOURCE CODE
if meter_type == "domestic":
if units <= 200:
rate = 5
elif units <= 400:
rate = 7.5
PAGE 19
else:
rate = 10
elif meter_type == "commercial":
if units <= 200:
rate = 10
elif units <= 400:
rate = 15
else:
rate = 20
else:
rate = 0
Electricity Bill
Consumer No: 22
Name: ATHARV JAIN
Address: ABC COLONY
Meter Type: domestic
Units Consumed: 399.0
Rate per Unit: 7.5
Total Bill: Rs. 2992.5
------------------------------------------------------------------------------------------------------------
Q20. Write a program to create a menu to do the following operations on a number
entered by user –
MENU
1. FIND ODD OR EVEN
2. FIND IT IS OF 3 DIGITS OR NOT
3. LAST DIGIT IS 7 OR NOT
4. EXIT
SOURCE CODE
PAGE 20
while True:
print("\nMENU")
print("1. FIND ODD OR EVEN")
print("2. FIND IF 3 DIGITS OR NOT")
print("3. LAST DIGIT IS 7 OR NOT")
print("4. EXIT")
choice = int(input("Enter choice: "))
if choice == 4:
break
num = int(input("Enter number: "))
if choice == 1:
print("Even" if num % 2 == 0 else "Odd")
elif choice == 2:
print("3-digit number" if 100 <= abs(num) <= 999 else "Not a 3-digit number")
elif choice == 3:
print("Last digit is 7" if abs(num) % 10 == 7 else "Last digit is NOT 7")
else:
print("Invalid choice")
OUTPUT:
MENU
1. FIND ODD OR EVEN
2. FIND IF 3 DIGITS OR NOT
3. LAST DIGIT IS 7 OR NOT
4. EXIT
Enter choice: 1
Enter number: 33
Odd
------------------------------------------------------------------------------------------------------------
Q21. Find the roots of a quadratic equation (Ax2 + Bx + C = 0).
SOURCE CODE
import math
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
d = b**2 - 4*a*c # discriminant
if d > 0:
root1 = (-b + [Link](d)) / (2*a)
root2 = (-b - [Link](d)) / (2*a)
print("Roots are real and different:", root1, root2)
elif d == 0:
root = -b / (2*a)
print("Roots are real and equal:", root)
else:
real_part = -b / (2*a)
imag_part = [Link](-d) / (2*a)
PAGE 21
print("Roots are complex:", f"{real_part} ± {imag_part}i")
OUTPUT:
Enter coefficient a: 2
Enter coefficient b: 4
Enter coefficient c: 2
Roots are real and equal: -1.0
------------------------------------------------------------------------------------------------------------
ITERATION-LOOPS
OUTPUT:
100 95 90 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 10
------------------------------------------------------------------------------------------------------------
[Link] 1,4,9,16, 25, ………………………….400
PAGE 22
SOURCE CODE
for i in range(1, 21):
print(i**2, end=" ")
print("\n")
OUTPUT:
1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400
------------------------------------------------------------------------------------------------------------
[Link] 1,8,27,64,125, ………………………….1000
SOURCE CODE
for i in range(1, 11):
print(i**3, end=" ")
print("\n")
OUTPUT:
1 8 27 64 125 216 343 512 729 1000
------------------------------------------------------------------------------------------------------------
[Link] 1,4,7,10,13,16,19……………………N
SOURCE CODE
N = int(input("Enter N: "))
a=1
while a <= N:
print(a, end=" ")
a += 3
print("\n")
OUTPUT:
Enter N: 38
1 4 7 10 13 16 19 22 25 28 31 34 37
------------------------------------------------------------------------------------------------------------
[Link] 1,2,4,7,11,16, ………………. N terms
SOURCE CODE
PAGE 23
N = int(input("Enter N: "))
a=1
diff = 1
for i in range(N):
print(a, end=" ")
diff += 1
a += diff
print("\n")
OUTPUT:
Enter N: 38
1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 300 325
351 378 406 435 465 496 528 561 595 630 666 703 741
------------------------------------------------------------------------------------------------------------
[Link] 1, -4, 7, -10, ……………………N terms
SOURCE CODE
N = int(input("Enter N: "))
num = 1
sign = 1
for i in range(N):
print(num * sign, end=" ")
num += 3
sign *= -1
print("\n")
OUTPUT:
Enter N: 38
1 -4 7 -10 13 -16 19 -22 25 -28 31 -34 37 -40 43 -46 49 -52 55 -58 61 -64 67 -70 73 -76
79 -82 85 -88 91 -94 97 -100 103 -106 109 -112
------------------------------------------------------------------------------------------------------------
[Link] your name N times.
PAGE 24
SOURCE CODE
name = input("Enter your name: ")
N = int(input("Enter N: "))
for _ in range(N):
print(name)
print("\n")
OUTPUT:
Enter your name: Atharv
Enter N: 5
Atharv
Atharv
Atharv
Atharv
Atharv
------------------------------------------------------------------------------------------------------------
[Link] first N odd Numbers, where N is entered by user.
SOURCE CODE
N = int(input("Enter N: "))
for i in range(1, 2*N, 2):
print(i, end=" ")
print("\n")
OUTPUT: Enter N: 5
13579
PAGE 25
print("\n")
OUTPUT:
Enter N: 5
2 4 6 8 10
------------------------------------------------------------------------------------------------------------
Q11. Find the sum of following series 5 + 10 + 15 + 20 +……………………………. +
50
SOURCE CODE
total = 0
for i in range(5, 51, 5):
total += i
print("Sum =", total, "\n")
OUTPUT: Sum = 275
------------------------------------------------------------------------------------------------------------
Q12. Find Sum of (1) + (1+2) + (1+2+3) + ………………………N terms.
SOURCE CODE
N = int(input("Enter N: "))
total = 0
for i in range(1, N+1):
total += sum(range(1, i+1))
print("Sum =", total, "\n")
OUTPUT:
Enter N: 5
Sum = 35
PAGE 26
for i in range(1, N+1):
total += x**i
print("Sum =", total, "\n")
OUTPUT:
Enter x: 3
Enter N: 5
Sum = 363
------------------------------------------------------------------------------------------------------------
[Link] the sum of 1/2 + 3/5 + 5/8 + ... N term
SOURCE CODE
N = int(input("Enter N: "))
num = 1
den = 2
total = 0
for _ in range(N):
total += num/den
num += 2
den += 3
print("Sum =", total, "\n")
OUTPUT:
Enter N: 5
Sum = 3.004220779220779
------------------------------------------------------------------------------------------------------------
PAGE 27
a, b = b, a+b
print("\n")
OUTPUT:
Enter N: 5
01123
------------------------------------------------------------------------------------------------------------
[Link] Age of N employees and then find how many are in the age group of
(a) 26 – 35 (b) 36 – 45 (c) 46 - 55
SOURCE CODE
N = int(input("Enter number of employees: "))
g1 = g2 = g3 = 0
for _ in range(N):
age = int(input("Enter age: "))
if 26 <= age <= 35:
g1 += 1
elif 36 <= age <= 45:
g2 += 1
elif 46 <= age <= 55:
g3 += 1
print("26-35:", g1, "36-45:", g2, "46-55:", g3, "\n")
OUTPUT:
Enter number of employees: 5
Enter age: 36
Enter age: 28
Enter age: 48
Enter age: 49
Enter age: 27
26-35: 2
36-45: 1
PAGE 28
46-55: 2
------------------------------------------------------------------------------------------------------------
[Link] a number and then display its table.
SOURCE CODE
num = int(input("Enter number: "))
for i in range(1, 11):
print(num, "x", i, "=", num*i)
print("\n")
OUTPUT:
Enter number: 5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
------------------------------------------------------------------------------------------------------------
Q18. Input a number and then display first 20 multiples of it.
SOURCE CODE
num = int(input("Enter number: "))
for i in range(1, 21):
print(num*i, end=" ")
print("\n")
OUTPUT:
Enter number: 2
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
PAGE 29
------------------------------------------------------------------------------------------------------------
Q19. Input a number and then display its factors.
SOURCE CODE
num = int(input("Enter number: "))
for i in range(1, num+1):
if num % i == 0:
print(i, end=" ")
print("\n")
OUTPUT:
Enter number: 4
124
------------------------------------------------------------------------------------------------------------
Q20. Input a number and then find and display its factorial.
SOURCE CODE
num = int(input("Enter number: "))
fact = 1
for i in range(1, num+1):
fact *= i
print("Factorial =", fact, "\n")
OUTPUT:
Enter number: 5
Factorial = 120
------------------------------------------------------------------------------------------------------------
[Link] a number and then find is it a prime number, composite number or not
prime nor composite or not?
SOURCE CODE
num = int(input("Enter number: "))
if num <= 1:
PAGE 30
print("Neither prime nor composite")
else:
for i in range(2, int(num**0.5)+1):
if num % i == 0:
print("Composite")
break
else:
print("Prime")
print("\n")
OUTPUT:
Enter number: 5
Prime
------------------------------------------------------------------------------------------------------------
Q22. Input a number and then find is it a perfect number? [Ex: 6 = 1 +2 +3]
SOURCE CODE
num = int(input("Enter number: "))
sum_div = 0
for i in range(1, num):
if num % i == 0:
sum_div += i
if sum_div == num:
print("Perfect number")
else:
print("Not perfect")
print("\n")
OUTPUT:
Enter number: 6
Perfect number
------------------------------------------------------------------------------------------------------------
PAGE 31
Q23. Input a number and then find sum of its digits. (Ex: Number is 186 then sum
of digits is 15)
SOURCE CODE
num = int(input("Enter number: "))
sum_d = sum(int(d) for d in str(num))
print("Sum of digits =", sum_d, "\n")
OUTPUT:
Enter number: 12
Sum of digits = 3
------------------------------------------------------------------------------------------------------------
[Link] a number and then find product of its digits. (Ex: Number is 286 then
product of digits is 96)
SOURCE CODE
num = int(input("Enter number: "))
prod = 1
for d in str(num):
prod *= int(d)
print("Product of digits =", prod, "\n")
OUTPUT:
Enter number: 123
Product of digits = 6
------------------------------------------------------------------------------------------------------------
Q25. Input a number and then find how many digits are in the given number.
SOURCE CODE
num = int(input("Enter number: "))
print("Number of digits =", len(str(num)), "\n")
OUTPUT:
PAGE 32
Enter number: 123
Number of digits = 3
------------------------------------------------------------------------------------------------------------
Q26. Input a number and then find and display its reverse. (Ex: Number is 7869
then reverse is 9687)
SOURCE CODE
num = int(input("Enter number: "))
print("Reverse =", int(str(num)[::-1]), "\n")
OUTPUT:
Enter number: 123
Reverse = 321
------------------------------------------------------------------------------------------------------------
[Link] a number and then find is it a palindrome number or not?
SOURCE CODE
num = int(input("Enter number: "))
if str(num) == str(num)[::-1]:
print("Palindrome")
else:
print("Not palindrome")
print("\n")
OUTPUT:
Enter number: 5
Palindrome
------------------------------------------------------------------------------------------------------------
Q28. Input a number (3 digits) and then find is it a Armstrong number or not?
(Sum of cube of digits = Number)
SOURCE CODE
num = int(input("Enter 3-digit number: "))
if sum(int(d)**3 for d in str(num)) == num:
print("Armstrong number")
PAGE 33
else:
print("Not Armstrong")
print("\n")
OUTPUT:
Enter 3-digit number: 123
Not Armstrong
------------------------------------------------------------------------------------------------------------
Q29. Find HCF (Highest common factor) of 2 numbers M and N, which are entered
by user.
SOURCE CODE
m = int(input("Enter first number: "))
n = int(input("Enter second number: "))
while n:
m, n = n, m % n
print("HCF =", m, "\n")
OUTPUT:
Enter first number: 12
Enter second number: 6
HCF = 6
------------------------------------------------------------------------------------------------------------
[Link] LCM (Least common multiple) of 2 numbers M and N, which are entered
by user
SOURCE CODE
m = int(input("Enter first number: "))
n = int(input("Enter second number: "))
a, b = m, n
while n:
m, n = n, m % n
hcf = m
lcm = (a*b)//hcf
PAGE 34
print("LCM =", lcm, "\n")
OUTPUT:
Enter first number: 12
Enter second number: 24
LCM = 24
------------------------------------------------------------------------------------------------------------
[Link] a program to display all prime numbers which are of 2 digits.
SOURCE CODE
for num in range(10, 100):
for i in range(2, int(num**0.5)+1):
if num % i == 0:
break
else:
print(num, end=" ")
print("\n")
OUTPUT:
11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
------------------------------------------------------------------------------------------------------------
[Link] a program to find sum of 1! + 3! + 5! + 7! +………………………. + N!
SOURCE CODE
N = int(input("Enter N: "))
def factorial(x):
f=1
for i in range(1, x+1):
f *= i
return f
total = sum(factorial(i) for i in range(1, N+1, 2))
print("Sum =", total, "\n")
OUTPUT:
Enter N: 6
PAGE 35
Sum = 127
------------------------------------------------------------------------------------------------------------
Q33. Find Sum of x – x2/2! + x3/3! – x4/4! + ……………………….. Nth term
SOURCE CODE
x = float(input("Enter value of x: "))
N = int(input("Enter number of terms N: "))
def factorial(num):
fact = 1
for i in range(1, num + 1):
fact *= i
return fact
total = 0
for i in range(1, N + 1):
term = (x ** i) / factorial(i)
if i % 2 == 0:
total -= term
else:
total += term
OUTPUT:
Enter value of x: 5
Enter number of terms N: 10
Sum of series = 0.13596092372133883
------------------------------------------------------------------------------------------------------------
[Link] a program to display first N prime numbers where N is entered by user. [
If N is 7 then it should display as 2 3 5 7 11 13 17]
PAGE 36
SOURCE CODE
N = int(input("Enter N: "))
count = 0
num = 2
while count < N:
for i in range(2, int(num**0.5)+1):
if num % i == 0:
break
else:
print(num, end=" ")
count += 1
num += 1
print("\n")
OUTPUT:
Enter N: 5
2 3 5 7 11
------------------------------------------------------------------------------------------------------------
PAGE 37
SOURCE CODE
N = int(input("Enter N for patterns: "))
Pattern 1
for i in range(1, N+1):
for j in range(i, 0, -1):
print(j, end=" ")
print()
Pattern 2
for i in range(1, N+1):
for j in range(1, i+1):
print(j, end=" ")
print()
PAGE 38
Pattern 3
for i in range(1, N+1):
print(" "*(N-i), end="")
for j in range(1, i+1):
print(j, end="")
print()
Pattern 4
for i in range(1, N+1):
print("* "*(2*i-1))
Pattern 5
for i in range(N, 0, -1):
for j in range(i, 0, -1):
print(j, end=" ")
print()
Pattern 6
for i in range(1, N+1):
for j in range(65, 65+i):
print(chr(j), end=" ")
print()
Pattern 7
num = 1
for i in range(1, N+1):
for j in range(i):
print(num, end=" ")
num += 1
PAGE 39
print()
Pattern 8
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(N, 0, -1):
print(chars[i-1:N])
OUTPUT:
Enter N for patterns: 5
1
21
321
4321
54321
1
12
123
1234
12345
1
12
123
1234
12345
PAGE 40
*
***
*****
*******
*********
54321
4321
321
21
1
A
AB
ABC
ABCD
ABCDE
1
23
456
7 8 9 10
11 12 13 14 15
PAGE 41
E
DE
CDE
BCDE
ABCDE
------------------------------------------------------------------------------------------------------------
PAGE 42