# Class 12 : Practical File Programs

## Write a python script to take input for a number and print its table?

```n=int(input("Enter any no "))
i=1
while(i<=10):
t=n*i
print(n," * ",i," = ",t)
i=i+1 ```

Output:

Enter any no 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
>>>

## Write a python script to take input for a number and print its factorial?

```n=int(input("Enter any no "))
i=1
f=1
while(i<=n):
f=f*i
i=i+1
print("Factorial = ",f) ```

Output:

Enter any no 5
Factorial = 120
>>>

## Write a python script to take input for a number check if the entered number is Armstrong or not.

```n=int(input("Enter the number to check : "))
n1=n
s=0
while(n>0):
d=n%10;
s=s + (d *d * d)
n=int(n/10)
if s==n1:
print("Armstrong Number")
else:
print("Not an Armstrong Number")  ```

Output:

Enter the number to check : 153
Armstrong Number
>>>

Output:

Enter the number to check : 152
Not an Armstrong Number
>>>

## Write a python script to take input for a number and print its factorial using recursion?

Sol:

```#Factorial of a number using recursion
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
#for fixed number
num = 7
#using user input
num=int(input("Enter any no "))
check if the number is negative
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of", num, "is", recur_factorial(num))```

Output:

Enter any no 5
The factorial of 5 is 120
>>>

## Write a python script to Display Fibonacci Sequence Using Recursion?

Sol:

```#Python program to display the Fibonacci sequence
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
nterms = 10
#check if the number of terms is valid
if (nterms <= 0):
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i)) ```

Output:

Fibonacci sequence:
0
1
1
2
3
5
8
13
21
34
>>>

### CBSE Class 12 @ Python

• Class 12 @ Python Theory Syllabus
• Class 12 @ Python Practical Syllabus
• Revision Tour
• Functions (Funcations, Inbuilt Functions, Python Modules, Python Packages)
• Inbuilt Functions
• Python Modules
• Python Packages
• Using Python Libraries
• Python Data File Handling
• Program Efficiency
• Data Structures In Python
• Data Visualization Using Pyplot
• Computer Networks
• MySQL
• Interface Python with SQL
• Society, Law and Ethics
• Web Development with Django
• Class 12 @ Python Sample Practical File
• Class 12 @ Python Sample Papers
• Class 12 @ Python Projects

### Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions
C Programs
C++ Programs

Important Pages