You are on page 1of 17

CENTRAL ACADEMY SCHOOL

SARDARPURA

NAME=MONISH SAHU

CLASS=11A

Subject=c.s
1 Program to find the area of a rectangle:

Length = float(input("Enter the length of the rectangle: "))


Width = float(input("Enter the width of the rectangle: "))

Area = Length * Width # Area is in float


print("The area of the rectangle is:", Area)
output:
Enter the length of the rectangle: 66
Enter the width of the rectangle: 66
The area of the rectangle is: 4356.0

2 Program to find the area of a triangle:


Base = float(input("Enter the base of the triangle: "))
Height = float(input("Enter the height of the triangle: "))

Area = 0.5 * Base * Height


print("The area of the triangle is:", Area)
output:
Enter the base of the triangle: 5
Enter the height of the triangle: 6
The area of the triangle is: 15.0

3 Program to find the area of a circle:

import math

radius = float(input("Enter the radius of the circle: "))

# Calculate the area of the circle


area = math.pi * radius ** 2

# Print the result


print("The area of the circle is:", area)
output:
Enter the radius of the circle: 6
The area of the circle is: 113.09733552923255
4 A dartboard of radius 10 units and the wall it is hanging on are represented using a
twodimensional coordinate system, with the board’s center at coordinate (0,0). Variables x and y
store the x-coordinate and the y-coordinate of a dart that hits the dartboard. Write a Python
expression using variables x and y that evaluates to True if the dart hits (is within) the dartboard,
and then evaluate the expression for these dart coordinates: a) (0,0) b) (10,10) c) (6, 6) d) (7,8)

x = float(input("Enter the x-coordinate of the dart: "))


y = float(input("Enter the y-coordinate of the dart: "))

dartboard_radius = 10
# Applying Pythagoras rule: coordinates should be less than the square of the radius
hits_dartboard = x**2 + y**2 <= dartboard_radius**2

print("The dart hits the dartboard:", hits_dartboard)


output:
Enter the x-coordinate of the dart: 4.5
Enter the y-coordinate of the dart: 4.6
The dart hits the dartboard: True

5 Write a Python program to convert temperature in degree Celsius to degree Fahrenheit. If


water boils at 100 degree C and freezes as 0 degree C, use the program to find out what is the
boiling point and freezing point of water on the Fahrenheit scale. (Hint: T(°F) = T(°C) × 9/5 + 32)

celsius = float(input("Enter the temperature in degree Celsius: "))


# T(°F) = T(°C) × 9/5 + 32
fahrenheit = (celsius * 9/5) + 32
print("The temperature in degree Fahrenheit is:", fahrenheit)
output:
Enter the temperature in degree Celsius: 77
The temperature in degree Fahrenheit is: 170.6

6 Write a Python program to calculate the amount payable if money has been lent on simple
interest.Principal or money lent = P, Rate of interest = R% per annum and Time = T years. Then
Simple Interest (SI) = (P x R x T)/ 100. Amount payable = Principal + SI. P, R and T are given as
input to the program
# taking input
principal = float(input("Enter the principal amount: "))
rate_of_interest = float(input("Enter the rate of interest (in percentage): "))
time = float(input("Enter the time period (in years): "))

# calculating simple interest (SI) = (P x R x T) / 100 and Amt = P + SI


simple_interest = (principal * rate_of_interest * time) / 100
amount_payable = principal + simple_interest
# printing the results
print("The simple interest is:", simple_interest)
print("The amount payable is:", amount_payable)
output:
Enter the principal amount: 100000
Enter the rate of interest (in percentage): 5
Enter the time period (in years): 10
The simple interest is: 50000.0
The amount payable is: 150000.0

7.Write a program to calculate in how many days a Work will be completed by three persons A, B
and C together. A, B, C take x days, y days and z days Respectively to do the job alone. The formula
to Calculate the number of days if they work together is xyz/(xy + yz + xz) days where x, y, and z
are given as input to the program.
x = float(input('Enter the number of days A takes to do the job alone: '))
y = float(input('Enter the number of days B takes to do the job alone: '))
z = float(input('Enter the number of days C takes to do the job alone: '))

days_together = (x * y * z) / (x * y + y * z + x * z)
print("The number of days it will take for A, B, and C to complete the work together is:",
days_together, "days")
output:
Enter the number of days A takes to do the job alone: 30
Enter the number of days B takes to do the job alone: 15
Enter the number of days C takes to do the job alone: 10
The number of days it will take for A, B, and C to complete the work together is: 5.0 days

8.Program to perform all arithmetic operations on two integers:


# Taking input
a = int(input("Enter the first integer: "))
b = int(input("Enter the second integer: "))

# Performing operations
addition = a + b
subtraction = a - b
multiplication = a * b
division = a / b # Use // for integer division in Python 3
modulus = a % b
exponentiation = a ** b

# Printing the results


print("Addition:", addition)
print("Subtraction:", subtraction)
print("Multiplication:", multiplication)
print("Division:", division)
print("Modulus:", modulus)
print("Exponentiation:", exponentiation)
output:
Enter the first integer: 5
Enter the second integer: 9
Addition: 14
Subtraction: -4
Multiplication: 45
Division: 0.5555555555555556
Modulus: 5
Exponentiation: 1953125

9. Program to swap two numbers using a third variable:

a = int(input("Enter the first number: "))


b = int(input("Enter the second number: "))

# Swapping values using a temporary variable


temp = a
a=b
b = temp

print("After swapping, the first number is:", a)


print("After swapping, the second number is:", b)
output:
Enter the first number: 3
Enter the second number: 5
After swapping, the first number is: 5
After swapping, the second number is: 3

10. Program to swap two numbers without using a third variable:

a = int(input("Enter the first number: "))


b = int(input("Enter the second number: "))

# Swapping values using a temporary variable


temp = a
a=b
b = temp

print("After swapping, the first number is:", a)


print("After swapping, the second number is:", b)
output:
Enter the first number: 3
Enter the second number: 5
After swapping, the first number is: 5
After swapping, the second number is: 3

11. Program to repeat the string ‘GOOD MORNING’ n times:

N = int(input("Enter the value of n: "))

Message = 'GOOD MORNING' * N


print(Message)
output:
Enter the value of n: 5
GOOD MORNINGGOOD MORNINGGOOD MORNINGGOOD MORNINGGOOD MORNING
12. Program to find the average of three numbers:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))

average = (num1 + num2 + num3) / 3


print("The average of the three numbers is:", average)
output:
Enter the first number: 5
Enter the second number: 9
Enter the third number: 12
The average of the three numbers is: 8.666666666666666

13 The volume of a sphere with radius r is 4/3πr3. Write a Python program to find the
volume of spheres with Radius 7cm, 12cm, 16cm, respectively.
import math
import math

radius1 = 7
radius2 = 12
radius3 = 16

Volume1 = (4/3) * math.pi * radius1**3


Volume2 = (4/3) * math.pi * radius2**3
Volume3 = (4/3) * math.pi * radius3**3

print("Volume of sphere with radius 7cm:", Volume1)


print("Volume of sphere with radius 12cm:", Volume2)
print("Volume of sphere with radius 16cm:", Volume3)
output:
Volume of sphere with radius 7cm: 1436.7550402417319
Volume of sphere with radius 12cm: 7238.229473870882
Volume of sphere with radius 16cm: 17157.284678805056

14. Write a program that asks the user To enter their name and age. Print a message
addressed to the user that tells the user the year in which they will turn 100 years old.

name = input("Enter your name: ")


age = int(input("Enter your age: "))

current_year = 2023 # Assuming the current year is 2023

year_when_100 = current_year + (100 - age)

print("Hello", name, "! You will turn 100 years old in the year", year_when_100)
output:
Enter your name: yash
Enter your age: 20
Hello yash ! You will turn 100 years old in the year 2103
15. The formula E = mc2 states that the equivalent energy € can be calculated as the Mass (m)
multiplied by the speed of light (c = about 3×108 m/s) squared. Write a program that
accepts the mass of an object and determines its energy

mass = float(input("Enter the mass of the object (in kg): "))


speed_of_light = 3e8 # 3 * 10**8, speed of light in m/s

energy = mass * speed_of_light**2


print("The energy of the object is:", energy, "joules")
output:
Enter the mass of the object (in kg): 60
The energy of the object is: 5.4e+18 joules

16 Presume that a ladder is put upright against A wall. Let variables length and angle store the
length of the ladder and the angle that it forms with the ground as it leans against the wall.

import math

Angle_degrees = float(input("Enter the angle formed by the ladder with the ground (in degrees): "))
Length = float(input("Enter the length of the ladder (in meters): "))

# Convert angle in degrees to radians


Angle_radians = math.radians(Angle_degrees)

# Calculate the height on the wall using trigonometry


Height_on_wall = Length * math.sin(Angle_radians)

print("The height at which the ladder reaches the wall is:", Height_on_wall, "meters")
output:
Enter the angle formed by the ladder with the ground (in degrees): 50
Enter the length of the ladder (in meters): 10
The height at which the ladder reaches the wall is: 7.66044443118978 meters
17. Write a program to read details like name, class, age of a student and then print the
details firstly in same line and then in separate lines. Make sure to have two blank lines in
these two different types of prints
name = input("Enter your name: ")
class_name = input("Enter your class: ")
age = int(input("Enter your age: "))

# Single line
print("Name:", name, "Class:", class_name, "Age:", age)

# Multiple lines with two blank lines in between


print("\n\nStudents Details:")
print("Name:", name)
print("Class:", class_name)
print("Age:", age)
output:
Enter your name: monish
Enter your class: 11
Enter your age: 16
Name: monish Class: 11 Age: 16

Students Details:
Name: monish
Class: 11
Age: 16

18. Program to convert distance in miles to kilometers:


miles = float(input("Enter the distance in miles: "))

# 1 km is equal to 0.621371 miles


kilometers = miles * 0.621371
print("The distance in kilometers is:", kilometers, "km")
output:
Enter the distance in miles: 20
The distance in kilometers is: 12.42742 km

19 Write a program that displays a joke. But display the punchline only when the user presses
enter key.(Hint. You may use input())

print('Why don’t scientists trust atoms?')


input("Press Enter to find out the punchline.")
print("Because they make up everything!")
output:
Why don"t scientists trust atoms?
Press Enter to find out the punchline.
Because they make up everything!
20. Program to find the number of days left in the current month:
from datetime import date, timedelta

today = date.today()
days_in_month = (date(today.year, today.month + 1, 1) - timedelta(days=1)).day
days_left = days_in_month - today.day

print("Number of days left in the current month:", days_left)


output:
Number of days left in the current month: 12
> 20

21. Write a program that generates the following output: 5


10
9
Assign value 5 to a variable using assignment operator (-) Multiply it with 2 to generate 10 and
subtract 1 to generate 9.Modify above program so as to print output as 5@10@9.

A = 5 # assignment operator
B = A * 2 # 10
C=B-1 #9

print(A)
print(B)
print(C)

# Using commas (with automatic space)


print(A, "@", B, "@", C)

# Using sep parameter to specify the separator without spaces


print(A, B, C, sep="@")
output:
5
10
9
5 @ 10 @ 9
5@10@9

22. Write a program to input a number and print its first five multiples

n = int(input("Enter a number: "))

multiple1 = n * 1
multiple2 = n * 2
multiple3 = n * 3
multiple4 = n * 4
multiple5 = n * 5

print("The first five multiples of", n, "are:", multiple1, multiple2, multiple3, multiple4, multiple5)
output:
Enter a number: 50
The first five multiples of 50 are: 50 100 150 200 250

23. Program to find the average marks:

marks1 = float(input("Enter marks for subject 1: "))


marks2 = float(input("Enter marks for subject 2: "))
marks3 = float(input("Enter marks for subject 3: "))
marks4 = float(input("Enter marks for subject 4: "))
marks5 = float(input("Enter marks for subject 5: "))

average_marks = (marks1 + marks2 + marks3 + marks4 + marks5) / 5


print("The average marks are:", average_marks)
output:
Enter marks for subject 1: 50
Enter marks for subject 2: 40
Enter marks for subject 3: 60
Enter marks for subject 4: 80
Enter marks for subject 5: 20
The average marks are: 50.0
24. Program to convert height from centimeters to feet and inches:

height_cm = float(input("Enter your height in centimeters: "))

# 1 foot = 12 inches, 1 inch = 2.54 cm


inches = height_cm / 2.54
feet = int(inches // 12)
remaining_inches = inches % 12

print("Your height is:", feet, "feet", remaining_inches, "inches")


output:
Enter your height in centimeters: 200
Your height is: 6 feet 6.740157480314963 inches

25. Program to print n, n^2, n^3, and n^4:

import math

n = int(input("Enter a number: "))


print("n:", n)
print("n^2:", n ** 2)
print("n^3:", n ** 3)
print("n^4:", n ** 4)

# Both methods can work


print("Square root of n:", math.sqrt(n))
print("Square root of n:", n ** 0.5)
output:
Enter a number: 53
n: 53
n^2: 2809
n^3: 148877
n^4: 7890481
Square root of n: 7.280109889280518
Square root of n: 7.280109889280518

26. Program to obtain the balance amount:

total_amount = float(input("Enter the total amount: "))


paid_amount = float(input("Enter the paid amount: "))

balance_amount = total_amount - paid_amount


print("The balance amount is:", balance_amount)
output:
Enter the total amount: 5000
Enter the paid amount: 3500
The balance amount is: 1500.0

27. Write a program to read three numbers in three variables and swap first two variables with
the sums of First and second, second and third numbers respectively. a=int(input(“enter the
number:”)) b=int(input(“enter the number:”)) c=int(input(“enter the number:”))

a=5
b = 10
c = 15

a += b
b += c

print("a:", a, "b:", b, "c:", c)


output:
a: 15 b: 25 c: 15

28.Program to compute compound interest:

principal = float(input("Enter the principal amount: "))


rate_of_interest = float(input("Enter the rate of interest (in percentage): "))
time = float(input("Enter the time period (in years): "))

compound_interest = principal * (1 + rate_of_interest / 100) ** time - principal

print("The compound interest is:", compound_interest)


output:
Enter the principal amount: 5000
Enter the rate of interest (in percentage): 8
Enter the time period (in years): 1
The compound interest is: 400.0

29.Program to demonstrate the use of statictis:

import statistics

data = [12, 15, 18, 20, 22, 25, 28, 30, 35]

mean = statistics.mean(data)
median = statistics.median(data)
mode = statistics.mode(data)
std_dev = statistics.stdev(data)
variance = statistics.variance(data)

print("Data:", data)
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
print("Standard Deviation:", std_dev)
print("Variance:", variance)
output:
Data: [12, 15, 18, 20, 22, 25, 28, 30, 35]
Mean: 22.77777777777778
Median: 22
Mode: 12
Standard Deviation: 7.429296362674223
Variance: 55.19444444444444

30. Program to demonstrate the use of random:

import random

# Generate a random floating-point number between 0 and 1


random_simple = random.random()

# Generate a random integer between 1 and 10 (inclusive)


random_int = random.randint(1, 10)

# Generate a random integer between 0 and 5 (exclusive)


random_range = random.randrange(5)

# Generate a random integer between 5 and 10 (exclusive)


random_range = random.randrange(5, 10)

# Generate a random integer between 5 and 20 with a step count of 2


random_range_step = random.randrange(5, 20, 2)

print("Random Simple (0-1):", random_simple)


print("Random Integer (1-10):", random_int)
print("Random Range (0-4):", random_range)
print("Random Range with Step (5-19, step 2):", random_range_step)
output:
Random Simple (0-1): 0.5566894177165946
Random Integer (1-10): 3
Random Range (0-4): 5
Random Range with Step (5-19, step 2): 13

31. Program to demonstrate the use of math:


import math

# Trigonometric functions
sin_result = math.sin(math.radians(30))
cos_result = math.cos(math.radians(60))
tan_result = math.tan(math.radians(45))

# Logarithmic functions
log_result = math.log(100, 10)
log10_result = math.log10(100)

# Mathematical constants
pi_value = math.pi
e_value = math.e

# Exponentiation using pow


pow_result = math.pow(2, 3)

# Absolute value using fabs giving always positive value


fabs_result = math.fabs(-5.6)

# Ceiling and floor using ceil and floor


ceil_result = math.ceil(7.3) # 8
floor_result = math.floor(7.8) # 7

# Square root using sqrt


sqrt_result = math.sqrt(25)
# Exponential function using exp
exp_result = math.exp(2) # e^2

print("2 raised to the power of 3:", pow_result)


print("Absolute value of -5.6:", fabs_result)
print("Ceiling of 7.3:", ceil_result)
print("Floor of 7.8:", floor_result)
print("Square root of 25:", sqrt_result)
print("Exponential function e^2:", exp_result)
print("Sine of 30 degrees:", sin_result)
print("Cosine of 60 degrees:", cos_result)
print("Tangent of 45 degrees:", tan_result)
print("Logarithm base 10 of 100:", log_result)
print("Logarithm base 10 of 100:", log10_result)
print("Value of pi:", pi_value)
print("Value of e:", e_value)
output:
2 raised to the power of 3: 8.0
Absolute value of -5.6: 5.6
Ceiling of 7.3: 8
Floor of 7.8: 7
Square root of 25: 5.0
Exponential function e^2: 7.38905609893065
Sine of 30 degrees: 0.49999999999999994
Cosine of 60 degrees: 0.5000000000000001
Tangent of 45 degrees: 0.9999999999999999
Logarithm base 10 of 100: 2.0
Logarithm base 10 of 100: 2.0
Value of pi: 3.141592653589793
Value of e: 2.718281828459045

32. Program to find the number is even and odd:


num = int(input("Enter a number: "))

# Check if the number is even or odd


if num % 2 == 0:
print(num, "is even.")
else:
print(num, "is odd.")
output:
Enter a number: 5
5 is odd.

33.Program to find if number is divisible by another


number: # Get user input for two numbers
num = int(input("Enter a number: "))
divisor = int(input("Enter the divisor: "))
# Check if the number is divisible by the divisor
if num % divisor == 0:
print(num, "is divisible by", divisor)
else:
print(num, "is not divisible by", divisor)
output:
Enter a number: 50
Enter the divisor: 5
50 is divisible by 5

34.Program to find the max of three number:


# Get user input for three numbers
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))

# Compare the three numbers using if statements


if num1 >= num2 and num1 >= num3:
maximum = num1
elif num2 >= num1 and num2 >= num3:
maximum = num2
else:
maximum = num3

print("The maximum of", num1, ",", num2, "and", num3,


"is:", maximum)
output:
Enter the first number: 5
Enter the second number: 20
Enter the third number: 30
The maximum of 5 , 20 and 30 is: 30

35.Program to sort of three number:


a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))

if a > b:
a, b = b, a
if b > c:
b, c = c, b
if a > b:
a, b = b, a

print(a, b, c)
output:
Enter the first number: 5
Enter the second number: 10
Enter the third number: 20
5 10 20

36. Program to print whether a given character is an uppercase or a lowercase character or a


digit or any other character # Get user input for a character char = input(“Enter a character:
“)

# Check the type of character using the 'and' operator if


char >= 'A' and char <= 'Z':
print(char, “is an uppercase character.”) elif
char >= 'a' and char <= 'z':
print(char, “is a lowercase character.”) elif
char >= '0' and char <= '9':
print(char, “is a digit.”) else:
print(char, “is another type of character.”)

or

# Get user input for a character


char = input(“Enter a character: “)

# Check the type of character using if-elif statements if


char.isupper():
print(char, “is an uppercase character.”) elif
char.islower():
print(char, “is a lowercase character.”) elif
char.isdigit(): print(char, “is a digit.”) else:
print(char, “is another type of character.”)
output:
Enter a character: lakshit
lakshit is a lowercase character.

37. Program to calculate and print roots of a quadratic equation: ax2+bx+c=0(a≠0) import
math

import math

# Input coefficients
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))

if a == 0:
print("Coefficient 'a' cannot be 0 for a quadratic equation.")
else:
# Calculate the discriminant
discriminant = b**2 - 4*a*c
if discriminant > 0:
# Two real and distinct roots
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
print("Roots:", root1, root2)
elif discriminant == 0:
# One real root (repeated)
root = -b / (2*a)
print("Root:", root)
else:
# Complex roots
real_part = -b / (2*a)
imaginary_part = math.sqrt(abs(discriminant)) / (2*a)
root1 = complex(real_part, imaginary_part)
root2 = complex(real_part, -imaginary_part)
print("Roots:", root1, root2)
output:
Enter coefficient a: 50
Enter coefficient b: 60
Enter coefficient c: 80
Roots: (-0.6+1.1135528725660044j) (-0.6-1.1135528725660044j)

38.Program to check if the year entered by the user is a leap year or not.
year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
output:
Enter a year: 2056
2056 is a leap year

You might also like