Practical Programs Class 11
Practical Programs Class 11
PROGRAM DEFINITION
To write a Python program that inputs a welcome message and displays it.
OUTPUT:
Enter your welcome message: Welcome to Python Coding Class
Welcome message: Welcome to Python Coding Class
PROGRAM 1:
2. LARGER/SMALLER NUMBER
PROGRAM DEFINITION
To write a Python program that inputs two numbers and displays both the larger and the smaller
number.
OUTPUT:
Enter the first number: 89
Enter the second number: 67
The larger number is: 89.0
The smaller number is: 67.0
PROGRAM 2:
# Input two numbers from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
PROGRAM DEFINITION
To Write a Python program that takes an input number and checks whether it is a prime or
composite number.
OUTPUT:
i)Enter a number: 5
5 is a prime number.
ii)Enter a number: 98
98 is a composite number.
PROGRAM 3:
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i=5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
if n <= 0:
print("Please enter a positive integer.")
else:
fibonacci_series = generate_fibonacci(n)
print("Fibonacci Series with {} terms:".format(n))
for term in fibonacci_series:
print(term, end=" ")
PROGRAM DEFINITION:
Write a program that compute the greatest common divisor and least common
multiple of two integers.
OUTPUT:
Enter the first integer: 56
Enter the second integer: 34
GCD of 56 and 34 is 2
LCM of 56 and 34 is 952
# Input string
input_string = input("Enter a string: ")
OUTPUT:
Enter a string: Analysing the Characters
Vowels: 7
Consonants: 15
Uppercase characters: 2
Lowercase characters: 20
___________________________________________________________________________________
7. Palindrome Check and Case Conversion for Strings
def is_palindrome(input_string):
# Remove spaces and convert to lowercase for a case-insensitive check
clean_string = input_string.replace(" ", "").lower()
def convert_case(input_string):
# Convert the input string to lowercase
lowercase_string = input_string.lower()
PROGRAM DEFINITION:
Write a program in Python Input a string and determine whether it is a
palindrome or not convert the case of characters in string.
OUTPUT:
Enter a string: Racecar
The input is a palindrome.
Lowercase: racecar
Uppercase: RACECAR
________________________________________________________________________
8. SWAP ELEMENTS
if len(num_list) % 2 != 0:
print("Please enter an even number of elements in the list.")
else:
for i in range(0, len(num_list), 2):
if i + 1 < len(num_list):
num_list[i], num_list[i + 1] = num_list[i + 1], num_list[i]
print("List with elements at even positions swapped with elements at odd positions:")
print(num_list)
PROGRAM DEFINITION:
Write a program that accept numbers and swap elements at the even location
with the elements at the odd location.
OUTPUT:
Enter a list of numbers separated by spaces: 4 67 5 8 45 66
List with elements at even positions swapped with elements at odd positions:
[67, 4, 8, 5, 66, 45]
____________________________________________________________________
9. Search for Element in List/Tuple
PROGRAM DEFINITION:
Write a Python program for Input a list/tuple of elements, search for a given
element in the list/tuple.
OUTPUT:
Enter a tuple of elements separated by spaces: 45 6 8 34 98
Enter the element to search for: 34
34 is found in the tuple
______________________________________________________________________
10. Display Names of Students with Marks Above 75
PROGRAM DEFINITION:
Write a program to Create a dictionary with the roll number, name and marks of
students in a class and display the names of students who have marks above 75.
OUTPUT:
Enter the number of students: 2
Enter roll number for student 1: 01
Enter name for student 1: Ravi
Enter marks for student 1: 78
Enter roll number for student 2: 02
Enter name for student 2: Vaishu
Enter marks for student 2: 45
Names of students with marks above 75:
Ravi
_________________________________________________________________
11. PATTERN
#pattern 1
print("Pattern 1:")
for i in range(1, 6):
print('*' * i)
#pattern 2
print("Pattern 2:")
for i in range(5, 0, -1):
for j in range(1, i + 1):
print(j, end='')
print()
#pattern 3
print("Pattern 3:")
for i in range(5):
for j in range(i + 1):
print(chr(65 + j), end='')
print()
PROGRAM DEFINITION:
Write a program to generate the following patterns.
OUTPUT:
Pattern 1:
*
**
***
****
*****
Pattern 2:
12345
1234
123
12
1
Pattern 3:
A
AB
ABC
ABCD
ABCDE
___________________________________________________________________
names = list()
n = int(input("Enter the number of names: "))
for i in range(n):
name = input("Enter name: ")
names.append(name)
print("Sorted Array:")
for i in range(n):
print(names[i])
PROGRAM DEFINITION:
Write a program in python to sort a given array of student names in alphabetical
order.
OUTPUT:
Enter the number of names: 5
Enter name: Hema
Enter name: Anu
Enter name: Zara
Enter name: Rahul
Enter name: Mohan
Sorted Array:
Anu
Hema
Mohan
Rahul
Zara
____________________________________________________________
13. FACTORIAL
PROBLEM DEFINITION:
Write a program in Python to find the factorial for a given number.
OUTPUT:
Please enter any number to find factorial: 6
The factorial of 6 is: 720
def factorial(num):
fact=1
for i in range(1, num+1):
fact=fact*i
return fact
number=int(input("Please enter any number to find factorial: "))
result=factorial(number)
print("The factorial of", number ,"is:", result)
__________________________________________________________________
14. RANDOM NUMBER GENERATOR
PROGRAM DEFINITION
To write a Python Program to generate random numbers between 1 to 6.
OUTPUT:
Rolling the dice...
You get... : 1
Do you want to continue (y/n) :y
Rolling the dice...
You get... : 5
Do you want to continue (y/n) :y
Rolling the dice...
You get... : 4
Do you want to continue (y/n) :n
import random
min = 1
max = 6
roll_again = "y"
while roll_again == "y" or roll_again == "Y":
print("Rolling the dice...")
val = random.randint (min, max)
print("You get... :", val)
roll_again = input("Do you want to continue (y/n) :")
_____________________________________________________________
# i)
x=float(input("Enter value of X:"))
n=int(input("Enter the value of n (for x ** n):"))
s=0
for a in range (n+1):
s+=x**a
print("SUM of First",n,"terms:",s)
PROGRAM DEFINITION:
Write a Python Program to input the value of x and n and print the sum of the
following series:
OUTPUT:
i) Enter value of X:3
Enter the value of n (for x ** n):2
SUM of First 2 terms: 13.0