0% found this document useful (0 votes)
74 views

Practical Programs 11 STD II TERM EXAM

The document contains 9 programming problems involving topics like factorials, Fibonacci sequence, multiplication tables, finding the greatest of three numbers, palindrome checking, and pattern generation using nested loops. For each problem, it provides the aim, algorithm, source code, sample input and expected output. The problems cover basic concepts like loops, strings, conditional statements, functions and pattern generation.

Uploaded by

toxiccreapers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Practical Programs 11 STD II TERM EXAM

The document contains 9 programming problems involving topics like factorials, Fibonacci sequence, multiplication tables, finding the greatest of three numbers, palindrome checking, and pattern generation using nested loops. For each problem, it provides the aim, algorithm, source code, sample input and expected output. The problems cover basic concepts like loops, strings, conditional statements, functions and pattern generation.

Uploaded by

toxiccreapers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ASAN MEMORIAL SENIOR SECONDARY SCHOOL, CH 06

II TERMINAL EXAMINATION – CSC (083) 07.12.2022

LIST OF PROGRAMS

1. Write a program to find the factorial of a number

SOURCE CODE:

num=int(input('Enter a number: '))


fact=1
if num<0:
print('Sorry, factorial does not exist for negative
numbers')
elif num==0:
print('The factorial of 0 is 1')
else:
for i in range(1,num+1):
fact=fact*i
print('The factorial of ',num,'is',fact)

Test Input:
Enter a number: 5

Expected Output:
The factorial of 5 is 120

2. Write a program to display Fibonacci sequence up to n-th term

SOURCE CODE:
n = int(input("Enter the value of n : "))
f1 = 0
f2 = 1
sum = 0
count = 1
print("Fibonacci Series: ", end = " ")
while count <= n:
print(sum, end = " ")
count += 1
f1 = f2
f2 = sum
sum = f1 + f2

OUTPUT :
Enter the value of n : 10
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34
3. Write a program to print the multiplication table from (1-10) in
python.

Source code :

print("Multiplication")
n=int(input("Enter the value of n : "))
for j in range(1,11):
print(n,'X',j," ",n*j)

Test Input:

Multiplication
Enter the value of n : 7

Expected Output:
7X1 7
7 X 2 14
7 X 3 21
7 X 4 28
7 X 5 35
7 X 6 42
7 X 7 49
7 X 8 56
7 X 9 63
7 X 10 70

4. Write a program to print sum of natural numbers

Source code:

print(Sum of n Natural numbers")


n=int(input("Enter the value of n : "))
s=0
for i in range(1,n+1):
s+=i
print(s)

Test Input:
Sum of n Natural numbers
Enter the value of n : 10

Expected Output:
1
3
6
10
15
21
28
36
45
55

5. Write a program to find the area and perimeter using choice

Source Code :
print("Area & Perimeter of circle")
print("1. Area 2. Perimeter")
ch=int(input("Enter your choice : "))
r=float(input("Enter your radius : "))
if ch==1:
a=3.14*r*r
print("Area of circle is : ",a)
elif ch==2:
p=2*3.14*r
print("Perimeter of circle is : ",p)
else:
print("Enter one or two")

Test Input:

Area & Perimeter of circle


1. Area 2. Perimeter
Enter your choice : 2
Enter your radius : 3
Expected Output:
Perimeter of circle is : 18.84
6. Write a program to find the greatest of three numbers
AIM: To write a python program to find the largest of three numbers.
ALGORITHM:
Step 1: Start
Step 2: Read three numbers in variable a, b and c.
Step 3: If a > b and a >c then display a is the greatest number.
Step 4: If b > a and b >c then display b is the greatest number.
Step 5: Else c is the smallest number.
Step 6: Stop
Source Code:
a=int(input("Enter First Number="))
b=int(input("Enter Second Number="))
c=int(input("Enter Third Number="))
if (a< b and a< c):
print("The greatest number is=", a )
elif (b < a and b < c):
print ("The greatest number is=", b)
else:
print ("The greatest number is=", c)

Test Input:
Enter First Number=60
Enter Second Number=48
Enter Third Number=50

Expected Output:
The greatest number is = 60

7. Write a program to find the smallest of two numbers.


AIM: To write a python program to find the largest of three numbers.
ALGORITHM:
Step 1: Start
Step 2: Input 2 numbers a and b
Step 3: Check if a is smaller than b. If true, print a. Otherwise print b.
Step 4: Stop
Source Code:
a=int(input("Enter First Number="))
b=int(input("Enter Second Number="))
if (a< b):
print("The smallest number is =", a )
else:
print ("The smallest number is =", b)
Test Input:
Enter First Number=60
Enter Second Number=48

Expected Output:

The smallest number is = 48

8. Write a program to generate the following patterns using nested


loop.
AIM:
To write a python program to Generate the following patterns using nested
loop.
ALGORITHM :
Step 1: Start
Step 2: Repeat step 3 to 5 until all value parse.
Step 3: Set i = 1 and check i < 6
Step 4: Set j = 1 and check i < i+1
Step 5: Print " * "
Step 6: Stop
SOURCE CODE :
for i in range(1,6):
for j in range(1,i+1):
print("*",end=" ")
print()

RESULT:
Thus, the given program has been executed and verified successfully

OUTPUT:
*
* *
* * *
* * * *
* * * * *

9. Write a program to print the given string is Palindrome or not.


AIM: To write the program to find the given string is palindrome or not.
PROGRAM ANALYSIS :
A palindrome is a string that is the same read forward or backward.
ALGORITHM:
Step 1: Start
Step 2: Input a string in variable line
Step 3: Call the function pali(line)
Step 4: Reverse the string using for loop and store it in str
Step 5: Check both the string line and str are same
Step 6: If both are same, display it is palindrome otherwise display not a
palindrome
Step 7: Stop

PROGRAM:
line=input(‘Enter a String : ‘)
st=''
n=len(str)
for k in range(n-1,-1,-1):
st=st+str[k] #copy from last
print('Reversed String : ',st)
if str==st:
print(str,'is a Palindrome')
else:
print(str,'Not a Palindrome')

Test Input:
Enter a String : malayalam
Reversed String : malayalam
Expected output:
malayalam is a Palindrome

You might also like