Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Python_Minor_Practical_Programs_Basic

The document contains practical Python programs for basic level tasks, including adding numbers, calculating square roots, and determining the area of a triangle. It also includes programs for checking even/odd numbers, leap years, and finding the greatest of three numbers. Additional exercises cover list slicing, grade calculation, character classification, palindrome checking, and a menu-driven program for number properties.

Uploaded by

Shaista Zarrin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python_Minor_Practical_Programs_Basic

The document contains practical Python programs for basic level tasks, including adding numbers, calculating square roots, and determining the area of a triangle. It also includes programs for checking even/odd numbers, leap years, and finding the greatest of three numbers. Additional exercises cover list slicing, grade calculation, character classification, palindrome checking, and a menu-driven program for number properties.

Uploaded by

Shaista Zarrin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Minor Practical Programs (Basic

Level)
Practical 1

Add Three Numbers Entered by the User


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
sum = num1 + num2 + num3
print("The sum is:", sum)

Square Root of a Number


import math
num = float(input("Enter a number: "))
sqrt = math.sqrt(num)
print("The square root is:", sqrt)

Area of a Triangle
base = float(input("Enter the base: "))
height = float(input("Enter the height: "))
area = 0.5 * base * height
print("The area is:", area)

Check if a Number is Even or Odd


num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")

Leap Year Check


year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
Find the Greatest of Three Numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if num1 >= num2 and num1 >= num3:
print("Greatest is", num1)
elif num2 >= num1 and num2 >= num3:
print("Greatest is", num2)
else:
print("Greatest is", num3)

Convert Kilometers to Meters


km = float(input("Enter distance in kilometers: "))
meters = km * 1000
print(km, "kilometers is", meters, "meters")

Practical 2

List Slice Example


my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print("Slice from index 2 to 6:", my_list[2:7])

Marks, Percentage, and Grade Calculation


marks = []
for i in range(5):
marks.append(float(input("Enter marks: ")))
total_marks = sum(marks)
percentage = (total_marks / 375) * 100
if percentage >= 90:
grade = "A"
elif percentage >= 75:
grade = "B"
elif percentage >= 60:
grade = "C"
elif percentage >= 45:
grade = "D"
else:
grade = "F"
print("Percentage:", percentage)
print("Grade:", grade)
Check if a Character is Vowel or Consonant
char = input("Enter a character: ").lower()
if char in 'aeiou':
print("Vowel")
elif char.isalpha():
print("Consonant")
else:
print("Invalid character")

Check if a String is a Palindrome


string = input("Enter a string: ")
if string == string[::-1]:
print("Palindrome")
else:
print("Not a palindrome")

Menu-Driven Program for Number Properties


while True:
print("1. Positive or Negative")
print("2. Odd or Even")
print("3. Prime")
print("4. Exit")
choice = int(input("Enter your choice: "))
if choice == 4:
break
num = int(input("Enter a number: "))
if choice == 1:
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
elif choice == 2:
if num % 2 == 0:
print("Even")
else:
print("Odd")
elif choice == 3:
if num <= 1:
print("Not Prime")
else:
prime = True
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
prime = False
break
if prime:
print("Prime")
else:
print("Not Prime")

You might also like