0% found this document useful (0 votes)
4 views5 pages

Final Lab File Sample

The document contains a Python lab assignment submitted by Ravi Kumar, detailing various programming tasks including triangle validation, finding the largest number, checking for palindromes, counting alphabets and digits in a string, and removing vowels from a string. Each task includes an aim, code implementation, and results. The document serves as a practical exercise in problem-solving using Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Final Lab File Sample

The document contains a Python lab assignment submitted by Ravi Kumar, detailing various programming tasks including triangle validation, finding the largest number, checking for palindromes, counting alphabets and digits in a string, and removing vowels from a string. Each task includes an aim, code implementation, and results. The document serves as a practical exercise in problem-solving using Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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:

You might also like