Python First Part
Python First Part
Python First Part
h= (a+b+c+d)/4
ifh >=90:
print ("A1"')
print ("A2")
print ("B1")
elif. h == 60:
print ("B2")
print ("C1")
print ("C2")
else:
print ("F")
2. To find sale price of an item with given cost and discount (%)
cost = float(input("Cost of the item: $"))
discount = float(input("Discount percentage: "))
3.To calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and circle.
import math
# Triangle
a, b, c = 3, 4, 5
triangle_perimeter = a + b + c
s = (a + b + c) / 2
triangle_area = math.sqrt(s * (s - a) * (s - b) * (s - c))
# Rectangle
length, width = 6, 8
rectangle_perimeter = 2 * (length + width)
rectangle_area = length * width
# Square
side = 5
square_perimeter = 4 * side
square_area = side ** 2
# Circle
radius = 2.5
circle_circumference = 2 * math.pi * radius
circle_area = math.pi * radius ** 2
# Output results
print("Triangle Perimeter:", triangle_perimeter)
print("Triangle Area:", triangle_area)
print("Rectangle Perimeter:", rectangle_perimeter)
print("Rectangle Area:", rectangle_area)
print("Square Perimeter:", square_perimeter)
print("Square Area:", square_area)
print("Circle Circumference:", circle_circumference)
print("Circle Area:", circle_area)
4.To calculate Simple and Compound interest.
principal_amount = 1000
interest_rate = 5
time_period = 2
compound_frequency = 1
# Input values
cost_price = 800
sell_price = 1000
GST calculation:
largest_number = max(numbers)
smallest_number = min(numbers)
third_largest = numbers[-3]
third_smallest = numbers[2]
10.To find the sum of squares of the first 100 natural numbers.
print("The sum of squares of the first 100 natural numbers is:", sum_of_squares)
13.To print the words starting with a alphabet in a user entered string.
state_capitals = {
"Alabama": "Montgomery",
"Alaska": "Juneau",
"Arizona": "Phoenix",
"Arkansas": "Little Rock",
"California": "Sacramento",}
students_marks = {
"John": [85, 90, 92, 88, 89],
"Alice": [78, 87, 80, 92, 85],
"Bob": [95, 88, 94, 90, 91],
}
print("Marks of John:", students_marks["John"])