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

Pythonques - Ipynb - Colaboratory

The document contains Python code snippets demonstrating: 1) A program to calculate the square root of a number and complex number. 2) A program to solve a quadratic equation. 3) A program to swap two variables. 4) A program to convert kilometers to miles. 5) Code raising a TypeError when an incorrect variable type is used.

Uploaded by

Nitesh Tiwari
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)
29 views

Pythonques - Ipynb - Colaboratory

The document contains Python code snippets demonstrating: 1) A program to calculate the square root of a number and complex number. 2) A program to solve a quadratic equation. 3) A program to swap two variables. 4) A program to convert kilometers to miles. 5) Code raising a TypeError when an incorrect variable type is used.

Uploaded by

Nitesh Tiwari
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/ 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