0% found this document useful (0 votes)
11 views

Class 11 Science Program

The document contains several programming exercises, including checking if a year is a leap year, performing basic arithmetic operations, calculating roots of a quadratic equation, and determining if three angles can form a triangle. Each section provides sample input and output to illustrate the functionality of the code. Additionally, it includes relevant mathematical concepts and conditions for each program.

Uploaded by

umamondal295
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Class 11 Science Program

The document contains several programming exercises, including checking if a year is a leap year, performing basic arithmetic operations, calculating roots of a quadratic equation, and determining if three angles can form a triangle. Each section provides sample input and output to illustrate the functionality of the code. Additionally, it includes relevant mathematical concepts and conditions for each program.

Uploaded by

umamondal295
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

4.

Write aprogram to check if the year entered by the user is aleap


yearor not.
Ans.
yr = int (input ("Enter a 4-digit year :"))
if yr %100 == 0: # century year check
if yr % 400 == :
leap = True
else :
leap = False
elif yr %4 == :
Sample Run
leap = True
else : Enter a 4-digit year :1900
leap = False 1900 is not a leap year
if leap == True: :2000
Enter a 4-digit year
print (yr, "is a leap year") 2000 is a leap year 13:16
vivo
Y200e
else :
year") 2025
print (yr, "is not aleap Enter a 4-digit year
:2019
2016 is a leap year 13,
Jan
Program that reads two numbers and an arithmetic operator and displavs the computed resut
9.7
:") )
um1 = float ( input( "Enter first number
rogram
num2 = float ( input( "Enter second number :"))
op = input("Enter operator [ + -*/ %]:")
result=0 Enter first number: 5
if op =='+: Enter second number: 2
result= num1 +num2 Enter operator [+ - */%]::
elif op ==: 5.0 * 2.0 = 10.0
result =num1- num2l e t o RESTART
elif op == *: Enter first number : 5
result = num1 * num2
Enter second number :2
elif op ==/':
Enter operator [ +- * /%]:
result =num1 /num2 5.0/ 2.0 = 2.5
elif op =='%': RESTART viVo
Y200e
sa 13:14
result= num1% num2 Enter first number: 5
else : 2025
2
Enter second number :*/%]
print ("Invalid operator!!") - :
Enter operator + 13,
print (num1, op, num2,', result) 5.0 % 2.0 = 1.0 Jan
CONTROL 267
FLOW OF
Anler9:
to calculate and print roots of aquadratic equation : ax? +bx +c=0 (a #0).
9.10 Program

Irogram importmath
equation, ax**2 +bx + c = 0, enter coefficients below")
print ("For quadratic :"))
a= int(input (" Enter a
b :"))
b= int(input (" Enter
C= int(input ("Enter c
:") ) NoTE
Youcan use sqrt( ) function of math package
if a ==0: to calculate squareroot of anumber. Use it as:
print ("Value of", a, 'should not be zero')
math.sqrt (<number or expression> )
print ("\n Aborting !!!!!!")
To use this function, add first line as
else :
import math to your program
delta =b *b -4 *a *c
if delta > 0 :
root1 = (-b+ math.sqrt (delta) ) / (2 * a)
root2 = (-b - math.sqrt (delta) ) / (2 * a)
print ("Roots are REAL and UNEQUAL")
print ("Root1 =", root1, ", Root2 =", root2)
elif delta == 0:
root1 =-b/ (2 * a)
print ("Roots are REAL and EQUAL")
print ("Root1 =", root1, ", Root2 =",
root1) NoTE
else : An if statement is also known as
IMAGINARY") a conditional.
print ("Roots are COMPLEX and

coefficients below
equation, ax**2 + bx + c= 0, enter
ror quadratic
Enter a :3
Enter b: 5
Enter c : 2
Roots are REAL and UNEQUAL
= -1.0
Rootl = -0.666666666667 , Root2
RESTART coefficients below
enter
bX + C= 0,
For quadratic equati on, ax**2 +
Enter a : 2
Enter b: 3
Enter c: 4
IMAGINARY
Roots are COMPLEX and
RESTART coefficients below
enter
ax**2 + bx + c= 0,
For quadratic equation,
Enter a : 2
Enter b: 4
Enter c : 2
Roots are REAL and EQUAL
OYRO0e Go ROot2 = 1
3, 2025, 13:11
Chd

programto input the value of xand nand


Write a the series :
29.
the sum of
print .4 -...... x"
1-x+x-x +x

Solution.
(input("Enter value of x: "))
y= int
int(input("Enter the power (n): "))
n=
S=0
Sign = +1
range(n + 1):
for a in * sign
term = (x ** a)
S+= term
Sign*= 1
first", n, "terms :", s)
print("Sum of
value of x: 5
Enter
power (n): 4
Enter the terms: 521
hen first 4
Sum of
and determine if theyform a
KInput three angles W
triangleor not.
Solution.
#check triangle from angles So
=0
angle1 = angle2 = angle3
float(input ("Enter angle 1 : "))
angle1 = angle 2 : "))
angle2 = float (input ("Enter
float(input ("Enter angle 3: "))
angle3 = 180 :
angle2 + angle3) ==
if (angle1 + triangle. ")
print ("Angles form a
else:
not form atriangle.")
print ("Angles do and n

You might also like