Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

05/06/2022, 02:06 .pythonQues.

ipynb - Colaboratory

Program to Find the Square Root

Program to Solve Quadratic Equation

Program to Swap Two Variables

Program to Convert Kilometers to Mile

num=int(input("enter the number"))
sqrt=num**0.5
print("the square root of %0.3f is %0.3f"%(num,sqrt))

enter the number9

the square root of 9.000 is 3.000

#for Complex number
import cmath
num=complex(input("enter the complex number"))
sqrt=cmath.sqrt(num)
print('the square root of {0} is {1:0.3f}+{2:0.3f}j'.format(num,sqrt.real,sqrt.imag

enter the complex number1+2j

the square root of (1+2j) is 1.272+0.786j

#solve quadratic equation ax**2+bx+c=0

import cmath

a=int(input("enter the vale of a"))
b=int(input("enter the vale of b"))
c=int(input("enter the vale of c"))
ans=(b**2)-(4*a*c)

pos_sol=(-b-cmath.sqrt(ans))/(2*a)

neg_sol=(-b+cmath.sqrt(ans))/(2*a)

print('The answer is {} and {}'.format(pos_sol,neg_sol))

enter the vale of a1

enter the vale of b5

enter the vale of c6

The answer is (-3+0j) and (-2+0j)

x=input("enter the first number")

y=input("enter the second number")

temp=x

https://colab.research.google.com/drive/1XHVIGAYFqJZiGQNbU21JeJLoQZ5qAU7s#scrollTo=F6KJTXZnlz1w&printMode=true 1/3
05/06/2022, 02:06 .pythonQues.ipynb - Colaboratory

x=y

y=temp

print("The value of x after swapping:{}".format(x))

print("The value of y after swapping:{}".format(y))

enter the first number5

enter the second number10

The value of x after swapping:10

The value of y after swapping:5

kilometers=float(input("enter the value in kilometer"))

factor_for_conversion=0.621371

miles=factor_for_conversion*kilometers

print("%0.2f kilometer is equal to %0.2f miles",(kilometers,miles))

enter the value in kilometer3.5

%0.2f kilometer is equal to %0.2f miles (3.5, 2.1747985)

x = "nitesh"

if not type(x) is int:

  raise TypeError("type your name properly")

--------------------------------------------------------------------------
-

TypeError Traceback (most recent call


last)
<ipython-input-5-87ddb2b5ba0f> in <module>()

1 if not type(x) is int:

----> 2 raise TypeError("type your name properly")

TypeError: type your name properly

https://colab.research.google.com/drive/1XHVIGAYFqJZiGQNbU21JeJLoQZ5qAU7s#scrollTo=F6KJTXZnlz1w&printMode=true 2/3
05/06/2022, 02:06 .pythonQues.ipynb - Colaboratory

Could not connect to the reCAPTCHA service. Please check your internet connection and reload to get a
reCAPTCHA challenge.

https://colab.research.google.com/drive/1XHVIGAYFqJZiGQNbU21JeJLoQZ5qAU7s#scrollTo=F6KJTXZnlz1w&printMode=true 3/3

You might also like