You are on page 1of 12

VELAMMAL VIDYALAYA ANNEXURE

CSC RECORD PROGRAMS-CLASS XI

PROGRAM 1
Aim:
To create a python program to display welcome message
Source code:
# take input from user
msg = input("Enter a welcome message: ")
# to display the welcome message
print(msg)
Output:
Enter a welcome message: Good morning
Good morning
PROGRAM 2
Aim:
To create a python program to find the G.C.D and L.C.M of two integers.
Source code:
x1 = int(input("Enter number1="))
y1= int(input("Enter number2="))
x=x1
y=y1
while(y1):
x1, y1 = y1, x1 % y1
print("The G.C.D is:",x1)
lcm = x*y/x1
print("The L.C.M. is", lcm)
Output:
Enter number1=24
Enter number2=36
The G.C.D is: 12
The L.C.M. is 72.0
PROGRAM 3
Aim:
To create a python program to print the following pattern
*
**
***
****
*****
Source code:
rows = int(input("Enter number of rows: "))
for i in range(rows):
for j in range(i+1):
print("* ", end="")
print("\n")
Output:
Enter number of rows: 5
*

**

***

****

*****
PROGRAM 4
Aim:
To create a python program to find the factorial of given number.
Source code:
# Python program to find the factorial of a number provided by the user.
# To take input from the user
num = int(input("Enter a number: "))
factorial = 1
# check if the number is negative, positive or zero
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):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output:
Enter a number: 5
The factorial of 5 is 120
PROGRAM 5
Aim:
To create a python program to find the largest number among the three input
numbers
Source code:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
Output:
Enter first number: 1
Enter second number: 6
Enter third number: 4
The largest number is 6.0
PROGRAM 6
Aim:
To create a python program to check if a number given is prime or not
Source code:
# Program to check if a number is prime or not
num = int(input("Enter a number: "))
# define a flag variable
flag = False
# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2, num):
if (num % i) == 0:
# if factor is found, set flag to True
flag = True
# break out of loop
break
# check if flag is True
if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")
Output:
Enter a number: 5
5 is a prime number
PROGRAM 7
Aim:
To create a python program to display the Fibonacci sequence up to n-th term
Source code:
nterms = int(input("How many terms? "))
# first two terms
n1, n2 = 0, 1
count = 0
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
Output:
How many terms? 10
Fibonacci sequence:
0
1
1
2
3
5
8
13
21
34
PROGRAM 8
Aim:
To create a python program to check if the string entered is palindrome or not
Source code:
# Program to check if a string is palindrome or not
my_str = input("Enter a string:")
# check if the string is equal to its reverse
if my_str==my_str[::-1]:
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
Output:
Enter a string:dad
The string is a palindrome.
PROGRAM 9
Aim:
To create a python program to sort a list in ascending and descending order
using bubble sort
Source code:
data = eval(input("Enter a list:"))
print("List before sorting:",data)
for i in range(len(data)):
for j in range(0, len(data) - i - 1):
if data[j] > data[j + 1]:
temp = data[j]
data[j] = data[j+1]
data[j+1] = temp
print('Sorted Array in Ascending Order:')
print(data)
for i in range(len(data)):
for j in range(0, len(data) - i - 1):
if data[j] < data[j + 1]:
temp = data[j]
data[j] = data[j+1]
data[j+1] = temp
print('Sorted Array in Descending Order:')
print(data)
Output:
Enter a list:[98,67,43,20,67]
List before sorting: [98, 67, 43, 20, 67]
Sorted Array in Ascending Order:
[20, 43, 67, 67, 98]
Sorted Array in Descending Order:
[98, 67, 67, 43, 20]
PROGRAM 10
Aim:
To create a python program to print the smallest and highest number from the
given tuple.
Source code:
num=eval(input("Enter a tuple containing numbers:"))
max_num=max(num)
min_num=min(num)
print("The highest number in the tuple:",max_num)
print("The smallest number in the tuple:",min_num)
Output:
Enter a tuple containing numbers:(6,9,2,7)
The highest number in the tuple: 9
The smallest number in the tuple: 2

You might also like