Programming for Problem Solving-II
Python lab
Submitted By -
Ravi Kumar
Roll no : 28240356
Section : CSE [C]
Panipat Institute of Engineering and Technology (PIET)
Panipat
Sr Program Signature
No
1. Write a Python program to accept three sides of a triangle as the
input and print whether the triangle is valid or not.
2. Write a Python program to find the largest among three numbers
3. Write a program to check if the given number is a palindrome
number
4. Write a program to count the number of alphabets and number of
digits in a string
5. Write a program to accept a string from the user, delete all vowels
from the string and display the result.
6. Given a string, write a Python program to find the largest substring
of uppercase characters and print the length of that
substring.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
Program 1
Aim : Write a Python program to accept three sides of a triangle as the input and print
whether the triangle is valid or not.
Code:
# Accept three sides of the triangle as input
a = float(input("Enter first side: "))
b = float(input("Enter second side: "))
c = float(input("Enter third side: "))
# Check the Triangle Inequality Theorem
if (a + b > c) and (a + c > b) and (b + c > a):
print("The triangle is valid.")
else:
print("The triangle is not valid.")
print(f"Code by Ravi , Roll : 28240328" )
Result:
Program 2
Aim : Write a Python program to find the largest among three numbers.
Code:
# Accept three numbers as input
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
# Find the largest number
if (a >= b) and (a >= c):
largest = a
elif (b >= a) and (b >= c):
largest = b
else:
largest = c
# Print the result
print("The largest number is:", largest)
print(f"Code by Ravi , Roll : 28240328" )
Result:
Program 5
Aim : Write a program to count the number of alphabets and number of digits in a
string
Code:
# Input string
input_string = "Hellowelcometo123 World456!"
# Initialize counters for alphabets and digits
alphabet_count = 0
digit_count = 0
# Iterate over each character in the string
for char in input_string:
# Check if the character is an alphabet (A-Z or a-z)
if ('a' <= char <= 'z') or ('A' <= char <= 'Z'):
alphabet_count += 1 # Increment alphabet count
# Check if the character is a digit (0-9)
elif '0' <= char <= '9':
digit_count += 1 # Increment digit count
# Output the results
print(f"Alphabets: {alphabet_count}")
print(f"Digits: {digit_count}")
print(f"Code by Ravi , Roll : 28240328" )
Result: