Simplified Computer Science Practical Template 1
Simplified Computer Science Practical Template 1
Exercise 1
Program
Question Number 01
A = int(input("Enter the first number"))
B = int(input("Enter the second number" )) WAP to find the greatest number
C = int(input("Enter the third number")) among the three inputed number
if (A>B):
if (A>C):
print(A,"is the greatest number ")
else:
print(C,"is the greatest number ") Output
else:
if(B>C):
print(B,"is the greatest number")
else:
print(C,"is the greatest number ")
Practical Exercise 2
QUESTION 04
WAP to check if the inputed number is
positive or negativie:
PROGRAM
num = float(input("Enter the number"))
if(num < 0):
print(num,"is negative")
elif(num > 0): Output
print(num,'is positive')
else:
print(num,'is zero')
Practical Exercise 5
QUESTION 05
WAP to print all the even numbers
PROGRAM between 10 to 20
Output
Practical Exercise 6
PROGRAM
Program Name
num = int(input("Enter a number: "))
if num < 0: Mention the specific name or title of the
print("Error: Factorial is not defined for program.
negative numbers.")
else:
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial of", num, "is:", fact)
Output
Practical Exercise 07
PROGRAM QUESTION 07
WAP that displays all the prime numbers
below 30
for num in range(2, 30):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
Output
Practical Exercise 8
PROGRAM QUESTION 08
WAP to accept a number and print its
num = int(input("Enter a number: ")) reverse order
reverse_num = 0
while num != 0:
remainder = num % 10
reverse_num = (reverse_num * 10) +
remainder
num = num // 10
Output
print("Reverse number:", reverse_num)
Practical Exercise 9
QUESTION
PROGRAM
WAP to print fibonacci series upto a
given limit:
i = int(input('enter the limit '))
x =0
y=1
z=1
print("fibonacci series\n")
print(x,y,end = ' ')
while(z<=i):
print(z,end = ' ') Output
x =y
y=z
z = x+y
Practical Exercise 10
QUESTION 10
PROGRAM
num = int(input("enter the number")) WAP to check if the inputed number
for i in range(2,num//2+1): is prime or not
if(num%i==0):
print(num,"is not a prime number")
break
else:
print(num,"is a prime number ")
Output
Practical Exercise 11
QUESTION 11
PROGRAM
WAP to check if the given number is
orig = int(input("enter the number ")) palindrome or not
num = orig
rev = 0
while (num > 0 ):
digit = num % 10
rev = rev * 10 + digit
num = int(num/10) Output
if (orig == rev):
print(orig,"is palindrome")
else:
print(orig,"is not palidrome")
Practical Exercise 12
PROGRAM QUESTION
WAP to convert decimal to binary
QUESTION
PROGRAM
WAP to check if the given number is
num = int(input("Enter a three digit
armstrong or not
number "))
f = num
sum =0
while(f > 0):
a = f%10
f = int(f/10)
sum = sum + (a**3)
if (sum == num):
print(num,"is an armstrong number") Output
else:
print(num,"is not a armstrong number")