Adwik Srivastava
9th H
200513
D.P.S Greater Faridabad Sector
81
PROGRAM 1.
a=1
b=2
c=3
d=4
e=5
f=(a+b+c+d+e)
print(f)
Output : 15
PROGRAM 2.
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
Input:2,3,4
Output:
The largest number is 4.0
PROGRAM 3.
num=int(input("Number:"))
if (num%2)==0:
print(“The Number Is Even")
else:
print(“The Number Is Odd")
Input:
2
Output:
The Number Is Even
PROGRAM 4.
character = input("Enter a character: ")
if character.isupper():
print(f"The character '{character}' is an uppercase character.")
elif character.islower():
print(f"The character '{character}' is a lowercase character.")
elif character.isdigit():
print(f"The character '{character}' is a digit.")
else:
print(f"The character '{character}' is a special character.")
Input: y
Output: The character 'y' is a lowercase character.
PROGRAM 5.
n = int(input("Enter the value of n: "))
sum_even = n * (n + 1)
print(f"The sum of the first {n} even numbers is: {sum_even}")
sum_odd = n * n
print(f"The sum of the first {n} odd numbers is: {sum_odd}")
Input: 4
Output:
20,16
PROGRAM 6.
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num, "is an Armstrong number")
else:
print(num, "is not an Armstrong number")
Input: 3
Output: 3 is not an Armstrong number
PROGRAM 7.
billing_amount = float(input("Enter the billing amount: "))
age = int(input("Enter the age: "))
if billing_amount > 10000 and age > 59:
discount = 0.15 * billing_amount
else:
discount = 0.10 * billing_amount
final_amount = billing_amount - discount
print(f"The billing amount is: Rs.{billing_amount}")
print(f"The discount applied is: {discount * 100}%")
print(f"The final billing amount after discount is: Rs.{final_amount}")
Input: 5444,58
Output: The billing amount is: Rs.5444.0
The discount applied is: 54440.0%
PROGRAM 8.
print(". .....")
print(".. ....")
print("... ...")
print(".... ..")
print("..... .")
Output:
. .....
.. ....
... ...
.... ..
..... .
PROGRAM 9.
num = float(input("Enter a number: "))
square = num * num
print(f"The square of the given number {num} = {square}")
Input:3
Output: The square of the given number 3.0 = 9.0
PROGRAM 10.
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = 0.5 * base * height
print(f"The area of the triangle with base {base} and height {height}
is {area}")
Input: 3,4
Output: The area of the triangle with base 3.0 and height 4.0 is 6.0
PROGRAM 11.
km=float(input("Length in Kilometres:"))
m=km*1000
print(m,"m")
Input: 4
Output: 4000.0 m
PROGRAM 12.
for i in range(1, 6):
print(f"5 x {i} = {5 * i}")
Output:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
PROGRAM 13.
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest (in percentage): "))
time = float(input("Enter the time period (in years): "))
simple_interest = (principal * rate * time) / 100
print(f"The simple interest for the principal amount Rs.{principal}, at
a rate of {rate}% for {time} years is Rs.{simple_interest}")
Input: 2,5,4
Output:
The simple interest for the principal amount Rs.2.0, at a rate of 5.0%
for 4.0 years is Rs.0.4
PROGRAM 14.
children_list = ["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha",
"Kartik"]
print("Original list of children selected for science quiz:")
print(children_list)
children_list.remove("Vikram")
children_list.append("Jay")
del children_list[1]
print("\nModified list after performing the tasks:")
print(children_list)
Output:
Original list of children selected for science quiz:
['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
Modified list after performing the tasks:
['Arjun', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']
PROGRAM 15
num = [23, 12, 5, 9, 65, 44]
print(len(num))
print(num[1:4])
print(num[-3:-6:-1])
even_numbers = [2*i + 1 for i in range(10)]
print(even_numbers)
List_1 = [10, 20, 30, 40]
List_1.extend([14, 15, 12])
List_1.sort()
print(List_1)
Output:
6
[12, 5, 9]
[9, 5, 12]
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]