Lecture 01

In [1]:
#Hello world!
print('hello world!')
hello world!
In [2]:
#data types and mathematical operators
a=9
b=7
c=5.6
print(a+b,a-c,a/b,a//b,a%b,a*c,a**b)
16 3.4000000000000004 1.2857142857142858 1 2 50.4 4782969

In [3]:
#input method
mess = str(input('Enter your name : '))
num1 = int(input('Enter an int number : '))
num2 = float(input('Enter a float number : '))
print('hello',mess,', your numbers are: int:',num1,'float:',num2)
Enter your name : ahmadi
Enter an int number : 2
Enter a float number : 3.6
hello ahmadi , your numbers are: int: 2 float: 3.6

Calculating $\dfrac{ax^2-3x}{x^3}$ :

In [4]:
a = float(input('Enter a : '))
x = float(input('Enter x : '))
print((a*x**2-3*x)/(5*x**3))
Enter a : 3.2
Enter x : 5.4
0.09794238683127571

Complex numbers $a+bj$ ($j$ is imaginary number):

In [5]:
c1=2+3j
c2=5+4j
print(c1,c2,c1+c2,c1*c2,c1/c2,abs(c1))
(2+3j) (5+4j) (7+7j) (-2+23j) (0.5365853658536587+0.17073170731707318j) 3.605551275463989
In [6]:
t=True
f=False
print(t,f)
print(type(t),type(f))
True False
<class 'bool'> <class 'bool'>

More examples:

In [7]:
#Complex numbers 2:
c1=2+3j
c2=5+4j
c3=5
c4=4j
a=c3+c4
print(c1,c2,c1+c2,c1*c2,c1/c2,abs(c1),a)
(2+3j) (5+4j) (7+7j) (-2+23j) (0.5365853658536587+0.17073170731707318j) 3.605551275463989 (5+4j)
In [8]:
#print in new lines:
print(' hi \n',2.3,'\n','last line.')
 hi 
 2.3 
 last line.