Professional Documents
Culture Documents
SARDARPURA
NAME=MONISH SAHU
CLASS=11A
Subject=c.s
1 Program to find the area of a rectangle:
import math
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
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): "))
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
# 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
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
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.
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
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): "))
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)
Students Details:
Name: monish
Class: 11
Age: 16
19 Write a program that displays a joke. But display the punchline only when the user presses
enter key.(Hint. You may use input())
today = date.today()
days_in_month = (date(today.year, today.month + 1, 1) - timedelta(days=1)).day
days_left = days_in_month - today.day
A = 5 # assignment operator
B = A * 2 # 10
C=B-1 #9
print(A)
print(B)
print(C)
22. Write a program to input a number and print its first five multiples
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
import math
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
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
import random
# 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
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
or
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: "))