You are on page 1of 4

8/26/2021 Untitled2.

ipynb - Colaboratory

#1.1 Practice basic arithmetic operations (+,-,*,/,//,%,**) on the numbers assigned to you
 
34+23
43-32
42*12
56/8
44//4
656%4
3**3

27

34+23   #addition

57

43-32   # subtration

11

42*12   #"*"used to multiply

504

56/8     #"/"to get quotient

7.0

44//4     #to get

11

656%4     #to find remainder

3**3      #3 raised to 3

27

#1.2 Write python code to input radius of circle and print area and perimeter of that circ
r=int(input("enter radius ")) #radius of cirle
import math
a=math.pi*r*r
print("area of circle is ",a) #area of circle

enter radius 3

area of circle is 28.274333882308138

https://colab.research.google.com/drive/1gRlA2iEXUXVvfKd8ZItTlIDUxZgN1koZ#scrollTo=Wt6QME7TX3gW&printMode=true 1/4
8/26/2021 Untitled2.ipynb - Colaboratory

#1.3 Write python code to input lengths of three sides of a triangle and print area of tri
a=float(input("enter the the side of triangle "))
b=float(input("enter the the side of triangle "))
c=float(input("enter the the side of triangle "))
s=(a+b+c)/2
print("perimeter of triangle is",s,"unit")
import math
a=math.sqrt(s*(s-a)*(s-b)*(s-c))
print("area of triangle is ",a,"square unit") #area of triangle by Heron's formula

enter the the side of triangle 3

enter the the side of triangle 4

enter the the side of triangle 5

perimeter of triangle is 6.0 unit


area of triangle is 6.0 square unit

#1.4 Input positive integer n and an integer k <= n. Verify the following properties.
#nCk = nCn-k
#nCk = n-1Ck-1
#n+1Ck = nCk-#1 + nCk
n=int(input("enter a positive number n: "))
k=int(input("enter a positive number k less than n: "))
import math
L=math.factorial(n)/((math.factorial(n-k))*(math.factorial(k)))
R=math.factorial(n)/((math.factorial(n-(n-k)))*(math.factorial(n-k)))
R==L
#a=math.factorial(n)/(math.factorial(k)*math.factorial(n-k))
#r=math.factorial(n-1)/(math.factorial((n-1)-(k-1))*(math.factorial(k-1))

enter a positive number n: 3

enter a positive number k less than n: 2

True

n=int(input("enter a positive number n: "))
A=math.factorial(n)/(math.factorial(k)*math.factorial(n-k))
k=int(input("enter a positive number k less than n: "))
B=math.factorial(n-1)/(math.factorial((n-1)-(k-1))*math.factorial(k-1))
A==B

enter a positive number n: 4

enter a positive number k less than n: 3

False

import math
s=math.factorial(n+1)/(math.factorial(k)*math.factorial(n+1-k))
t=(math.factorial(n)/(math.factorial(n-(k-1))*math.factorial(k-1)))+(math.factorial(n)/(ma
s==t

True

#1.5 Write a Python code to enter coefficients a, b, c of a quadratic equation axˆ2 + bx+c 
 
 
a=int(input("enter the coefficient of x square "))
https://colab.research.google.com/drive/1gRlA2iEXUXVvfKd8ZItTlIDUxZgN1koZ#scrollTo=Wt6QME7TX3gW&printMode=true 2/4
8/26/2021 Untitled2.ipynb - Colaboratory
( p ( q ))
b=int(input("enter the coefficient of x "))
c=int(input("enter the constant "))
import cmath
d=(b**2)-(4*a*c)
x1=(-b-math.sqrt(d))/(2*a)
x2=(-b+math.sqrt(d))/(2*a)
print("the first solution is ",x1)
print("the second solution is ",x2)

enter the coefficient of x square 1

enter the coefficient of x -5

enter the constant 6

the first solution is 2.0

the second solution is 3.0

#1.6 Write a Python code to enter real and imaginary parts of complex number z and print m
#z=x+yi
import cmath
x=int(input("enter the no x "))
y=int(input("enter the no y "))
d=math.sqrt(x**2+y**2)
print("the modulus of complex no z is ",d)
z=complex(x,y)
m=abs(z)
print("the modulus of complex no z is ",m)
w=cmath.polar(z)
print("the modulus and argument of complex no:",end="")
print(w)
 

enter the no x 3

enter the no y 4

the modulus of complex no z is 5.0

the modulus of complex no z is 5.0

the modulus and argument of complex no:(5.0, 0.9272952180016122)

https://colab.research.google.com/drive/1gRlA2iEXUXVvfKd8ZItTlIDUxZgN1koZ#scrollTo=Wt6QME7TX3gW&printMode=true 3/4
8/26/2021 Untitled2.ipynb - Colaboratory

check 7s completed at 6:10 PM

https://colab.research.google.com/drive/1gRlA2iEXUXVvfKd8ZItTlIDUxZgN1koZ#scrollTo=Wt6QME7TX3gW&printMode=true 4/4

You might also like