Python Program List For Autonomous
Python Program List For Autonomous
List of Experiments
1. Write a Python program to find the largest among the three numbers.
2. Write a python program to accept three sides of a triangle as the input and print whether
the triangle is valid or not.
3. Write a program to check if the given number is a palindrome number.
4. Write a program to reverse a user entered no and determine whether the original and
reversed no’s are equal or not.
5. Write a program to count the no of alphabets and no of digits in a string.
6. Write a program to accept a string from the user, delete all vowels from the string and
display the result.
7. Given a string, write a Python program to find the largest substring of uppercase
characters and print the length of that substring.
8. Write a program to create the following 3 lists:
A list of names.
A list of employee’s ids.
A list of salaries.
From these lists, generate 3 tuples - one containing all names, another containing all ids
and third containing all salaries. Also, from the three created lists, generate and print a
list of tuples containing name, ids and salaries.
9. Write a program to create a set containing 10 randomly generated nos in the range 15 to
40. Count how many of these nos are less than 30. Delete all nos greater than 35.
10. Create a dictionary of 10 usernames and passwords. Receive the username and password
from the keyboard and search for them in the dictionary. Based on whether a match is
found, print an appropriate message on the screen.
11. Write a program that defines a function compute ( ) that calculates the value of n + nn +
nnn + nnnn, where n is digit received by the function. Test the function for digits 4 and 7.
12. Write a Python program to demonstrate the use of lambda functions with map, filter, and
reduce.
13. Write a Python program to handle a Zero Division Error exception when dividing a
number by zero.
14. Write a Python program that prompts the user to input an integer and raises a Value Error
exception if the input is not a valid integer.
15. Write a Python program to create a numpy array of given shapes and perform basic
mathematical operations.
16. Write a Python program to perform group by and aggregation on a Pandas data frame.
17. Create Box plot, Scatter Plot and Histogram with Matplotlib.
18. Create Pair plot, Heatmap and Distribution plot with Seaborn.
1. Write a Python program to find the largest among the three numbers.
Logic Explanation:
To determine the largest of three numbers, we compare them using conditional statements.
We take input for three numbers separately and then compare them. We use if-elif-else
conditions to check which number is the greatest.
Example:
Input: 10, 25, 15
Comparison: 25 is greater than 10 and 15
Output: 25
2. Write a python program to accept three sides of a triangle as the input and print
whether the triangle is valid or not.
Logic of the program:
# 1. Take three integer inputs representing the sides of a triangle.
# 2. Check the triangle validity condition: The sum of any two sides must be greater than the
third side.
# 3. If the condition is met, print that the triangle is valid; otherwise, print that it is invalid.
# Example:
# Input: 3, 4, 5
# Output: The given sides form a valid triangle.
# Input: 1, 2, 3
# Output: The given sides do not form a valid triangle.
Logic Explanation:
A palindrome number reads the same forward and backward. We convert the number to a
string, reverse it, and check if it matches the original.
Example:
Input: 121
Reversed: 121
Output: Palindrome
4. Write a program to reverse a user entered no and determine whether the original and
reversed no’s are equal or not.
Logic of the program:
1. Take an integer input from the user.
2. Extract digits one by one from the number using modulus and division.
3. Construct the reversed number by multiplying the current reversed number by 10 and
adding the extracted digit.
4. Compare the original number with the reversed number to check if it is a palindrome.
5. Display the reversed number and the result.
# Example:
# Input: 121
# Reversed: 121
# Output: The original and reversed numbers are the same (Palindrome).
# Example:
# Input: "Hello123"
# Output: Alphabets: 5, Digits: 3
alphabet_count = 0
digit_count = 0
6. Write a program to accept a string from the user, delete all vowels from the string and
display the result.
We iterate over the string and remove characters that are vowels by checking against a
predefined set of vowels.
Example:
Input: Hello World
Vowels removed: Hll Wrld
Output: Hll Wrld
# Defining vowels
vowels = "aeiouAEIOU" # String containing all vowels (both lowercase and uppercase)
Output:
Enter a string: Hello World
String without vowels: Hll Wrld
7. Given a string, write a Python program to find the largest substring of uppercase
characters and print the length of that substring.
Logic Explanation:
We traverse the string and count the length of contiguous uppercase letters to find the largest
uppercase sequence.
Example:
Input: abcDEFghIJ
Longest Uppercase Substring: DEF (length: 3)
Output: 3
Output:
Enter a string: abcDEFghIJ
Longest uppercase substring length: 3
Logic Explanation:
We store employee data in lists, then convert them into tuples and a list of tuples.
Example:
Input: Alice (101, 50000), Bob (102, 60000), Charlie (103, 70000)
Tuples: ('Alice', 'Bob', 'Charlie'), (101, 102, 103), (50000, 60000, 70000)
List of Tuples: [('Alice', 101, 50000), ('Bob', 102, 60000), ('Charlie', 103, 70000)]
# Printing results
print("Tuples:", name_tuple, id_tuple, salary_tuple)
print("Employee Data:", employee_data)
9. Write a program to create a set containing 10 randomly generated nos in the range 15
to 40. Count how many of these nos are less than 30. Delete all nos greater than 35.
Logic:
# 1. Generate a set of 10 unique random numbers between 15 and 40.
# 2. Count how many numbers are less than 30.
# 3. Remove numbers greater than 35.
# 4. Display the results: the original set, count of numbers < 30, and the modified set.
# Example:
# Generated Set: {18, 22, 35, 40, 27, 29, 33, 19, 38, 25}
# Count of numbers less than 30: 6
# Set after deleting numbers greater than 35: {18, 22, 35, 27, 29, 33, 19, 25}
import random
# Generate a set of 10 unique random numbers between 15 and 40
# However, since a set only keeps unique values, it may not always end up with exactly 20
elements (some numbers may repeat and get discarded).
random_numbers = {random.randint(15, 40) for _ in range(20)}
print("Generated Set:", random_numbers)
Logic Explanation:
We store usernames and passwords in a dictionary and check user input against it.
Example:
Input: username=user1, password=pass1
Dictionary: {"user1": "pass1", "user2": "pass2"}
Output: Login successful
11. Write a program that defines a function compute ( ) that calculates the value of n + nn +
nnn + nnnn, where n is digit received by the function. Test the function for digits 4 and
7.
Logic Explanation:
We define a function compute() that generates terms by converting the number to a string and
repeating it to form nn, nnn, and nnnn. We then convert them back to integers and sum them
up.
Example:
Input: 4
Computation: 4 + 44 + 444 + 4444 = 4936
Output: 4936
Output:
Enter a digit: 4
Computed value: 4936
12. Write a Python program to demonstrate the use of lambda functions with map, filter,
and reduce.
lambda functions are small, anonymous functions defined using the lambda keyword. They
are often used in conjunction with functions like map(), filter(), and reduce() to write concise
and readable code.
# List of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Output
Squared Numbers: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Even Numbers: [2, 4, 6, 8, 10]
Sum of Numbers: 55
13. Write a Python program to handle a Zero Division Error exception when dividing a
number by zero.
Logic:
1. Take two numbers as input – a numerator and a denominator.
2. Try to divide the numerator by the denominator using the / operator.
3. Use a try-except block to handle the division.
4. If the denominator is zero, catch the ZeroDivisionError and print an appropriate
message.
5. Otherwise, print the result of the division.
Example:
Input: numerator = 10, denominator = 0
Expected Output: "Error: Cannot divide by zero!"
try:
# Taking input values
numerator = int(input("Enter numerator: "))
denominator = int(input("Enter denominator: "))
# Attempting division
result = numerator / denominator
except ZeroDivisionError:
print("Error: Cannot divide by zero!")
Enter numerator: 10
Enter denominator: 2
Output
Result: 5.0
Enter numerator: 10
Enter denominator: 0
Output
Error: Cannot divide by zero!
14. Write a Python program that prompts the user to input an integer and raises a Value
Error exception if the input is not a valid integer