Python Installation and Documentation
Aim:
☛ Start a Python interpreter and use it as a Calculator.
Solution :
To Start the Python interpreter in your Linux (Ubuntu) system, open terminal by pressing Ctrl + ALT + T and then type following command press enter.
$ python3 And then type following
Integer to Integer :
>>> a = 10
>>> b = 30
>>> print ( type ( a ) )
< class ' int ' >
>>> print ( type ( b ) )
< class ' int ' >
>>> print ( a + b )
40
>>> print ( a - b )
-20
>>> print ( a * b )
300
>>> print ( a / b )
0.3333333333333333
>>> print ( a % b )
10
>>> print ( a ** b )
1000000000000000000000000000000
>>> print ( a // b )
0
Integer to Float :
>>> a = 10
>>> b = 3.25
>>> print (type(a))
< class ' int ' >
>>> print (type(b))
< class ' float ' >
>>> print ( a + b )
13.25
>>> print ( a - b )
6.75
>>> print ( a * b )
32.5
>>> print ( a / b )
3.076923076923077
>>> print ( a % b )
0.25
>>> print ( a ** b )
1778.2794100389228
>>> print ( a // b )
3.0
Float to Float :
>>> a = 6.78
>>> b = 2.34
>>> print (type(a))
< class ' float ' >
>>> print ( type ( b ) )
< class ' float ' >
>>> print ( a + b )
9.120000000000001
>>> print ( a - b )
4.44
>>> print ( a * b )
15.8652
>>> print ( a / b )
2.897435897435898
>>> print ( a % b )
2.1000000000000005
>>> print ( a ** b )
88.12060773350571
>>> print ( a // b )
2.0
Integer to String :
>>> a = 6
>>> b = " python "
>>> print ( type ( a ) )
< class ' int ' >
>>> print ( type ( b ) )
< class ' str ' >
>>> print ( a + b )
TypeError: unsupported operand type(s) for + : ' int ' and ' str '
>>> print ( a - b )
TypeError: unsupported operand type(s) for - : ' int ' and ' str '
>>> print ( a * b )
python python python python python python
>>> print ( a / b )
TypeError: unsupported operand type(s) for / : ' int ' and ' str '
>>> print ( a % b )
TypeError: unsupported operand type(s) for % : ' int ' and ' str '
>>> print ( a ** b )
TypeError: unsupported operand type(s) for ** : ' int ' and ' str '
>>> print ( a // b )
TypeError: unsupported operand type(s) for // : ' int ' and ' str '
String to String :
>>> a = " python "
>>> b = " Programming "
>>> print ( type ( a ) )
< class ' str ' >
>>> print ( type ( b ) )
< class ' str ' >
>>> print ( a + b )
python Programming
>>> print ( a - b )
TypeError: unsupported operand type(s) for - : ' str ' and ' str '
>>> print ( a * b )
TypeError: unsupported operand type(s) for * : ' str ' and ' str '
>>> print ( a / b )
TypeError: unsupported operand type(s) for / : ' str ' and ' str '
>>> print ( a % b )
TypeError: unsupported operand type(s) for % : ' str ' and ' str '
>>> print ( a ** b )
TypeError: unsupported operand type(s) for ** : ' str ' and ' str '
>>> print ( a // b )
TypeError: unsupported operand type(s) for // : ' str ' and ' str '
Integer to Complex :
>>> a = 9
>>> b = 3 + 4j
>>> print ( type ( a ) )
< class ' int ' >
>>> print ( type ( b ) )
< class ' complex' >
>>> print ( a + b )
( 12 + 4j )
>>> print ( a - b )
( 6 - 4j )
>>> print ( a * b )
( 27 + 36j )
>>> print ( a / b )
( 1.08 - 1.44j )
>>> print ( a % b )
TypeError: unsupported operand type(s) for % : ' int ' and ' complex '
>>> print ( a ** b )
( - 586.5166552058375 + 432.9425056126467j )
>>> print ( a // b )
TypeError: unsupported operand type(s) for //: ' int ' and ' complex '
Float to Complex :
>>> a = 4.83
>>> b = 3 + 4j
>>> print ( type ( a ) )
< class ' float ' >
>>> print ( type ( b ) )
< class ' complex' >
>>> print ( a + b )
( 7.83 + 4j )
>>> print ( a - b )
( 1.83 - 4j )
>>> print ( a * b )
( 14.49 + 19.32j )
>>> print ( a / b )
TypeError: unsupported operand type(s) for / : ' int ' and ' complex '
>>> print ( a % b )
TypeError: unsupported operand type(s) for % : ' int ' and ' complex '
>>> print ( a ** b )
( 112.66380061063158 + 1.8253767513645904j )
>>> print ( a // b )
TypeError: unsupported operand type(s) for //: ' int ' and ' complex '
๐ป Run This Python Program
Python Installation and Documentation
The selected Python program is loaded
automatically into the editor.
Edit the program, provide input if required
and click Run.
The compiler is embedded using OneCompiler.
Your Python program runs inside the embedded
Python environment; Study Glance does not execute
Python code directly on your web server.