Automata Lab Report 2
Automata Lab Report 2
Python is an interpreted , high level, general purpose programming language, created by Guido
Van Rossum and first released in 1991, Python's design philosophy emphasizes code
readability with its notable use of significant whitespace. Its language constructs and object
oriented approach aim to help programmers write clear, logical code for small and large-scale
projects.
Python is dynamically typed and garbage collected. It supports multiple programming paradigms,
including procedural, object-oriented, and functional programming. Python is often described as a
"batteries included" language due to its comprehensive standard library.
Implementation:
I have implemented the algorithm according to above theory. The tools I used here:
Python
Environment : Anaconda
1.2 input():
Methodology:
In python input() function takes input from users and by evaluating expression it
automatically identifies whether the input is a string or a number.
Source Code:
1. in= input("Enter whatever you want: ")
2. print(in)
3. print(type(in))
4. n= int(in)
5. print(n)
6. print(type(n))
2|Page
Source Code:
1. for i in range(0,10,1):
2. print(i)
1.4 if condition:
Methodology:
In Python, it is mandatory to obey the indentation rules. For creating compound statements,
the indentation will be utmost necessary. We can understand the body of if condition in
python using indentation.
Source Code:
1. #for loop in python
2. for i in range(0,10,1):
3|Page
3. print(i)
4. if i%2==0:
5. print(i,"is even")
Implementation:
I have implemented the algorithm according to above theory. The tools I used here:
Python
Environment : Anaconda
As we open Jupyter notebook for writing code, we can see this interface and in
the In[]: section we have to insert our script. The NumPy arrays will be the keyway of
implementing the entire NumPy library.
Source Code:
1. import numpy as np
2. mat1 = np.array( [ (1,3,5,7),(2,4,6,8),(1,1,2,3) ])
3. print(mat1)
4. dimention = mat1.shape
5. print(dimention)
6. dimention_row = mat1.shape[0]
7. print(dimention_row)
8. dimention_row = mat1.shape[0]
9. print(dimention_row)
[[1 3 5 7]
[2 4 6 8]
[1 1 2 3]]
(3, 4)
3
Source Code:
1. import numpy as np
2. mat1 = np.array( [ (1,3,5,7),(2,4,6,8),(1,1,2,3) ])
3. mat2 = np.array( [ (1,9,7),(4,5,6),(7,4,1),(2,5,8) ])
4. mat3 = np.dot(mat1,mat2)
5. print(mat3)
6. mat4 = np.zeros((4,3))
7. print(mat4)
5|Page
[[ 62 79 86]
[ 76 102 108]
[ 25 37 39]]
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
Implementation:
I have implemented the algorithm according to above theory. The tools I used here:
Python
Environment : Anaconda
3.1 plot():
Source Code:
1. #matplot
2. %matplotlib inline
3. import numpy as np
4. import matplotlib.pyplot as plt
5. x = np.array([1,3,5,7])
6. y = np.array(x**2)
7. plt.plot(x,y)
8. plt.show()
6|Page
3.2 plot():
Source Code:
1. #matplot
2. %matplotlib inline
3. import numpy as np
4. import matplotlib.pyplot as plt
5. '''''''
6. x = np.array([1,3,5,7])
7. #y = np.array(x**2)
8. y = np.array(np.exp(x))
9. '''
10. x = np.arange(0,10,0.4)
11. y = np.array(np.exp(x))
12. plt.plot(x,y, 'r--')
13. plt.show()
7|Page
I have implemented the algorithm according to above theory. The tools I used here:
Python
Environment : Anaconda
4.1 re.findall():
Source Code:
1. import re
2. 2. data = '''''''
3. 3. Hello everyone, good morning, I am Faruk and I am from RUET.
4. 4. I meet Ronaldo last 17/Jan/2020 and got this phone number +8801725345621 , his man
age
5. r gaves me another phone number +8801955377859
6. '''
7. date_pattern = re.compile(r'\d+/[A-Za-z]+/\d{4}')
8. dates = date_pattern.findall(data)
9. print(dates)
10. phone_pattern = re.compile(r'\+[8][8][0][1][3|5|7|8|9]\d{8}')
11. phone_number = phone_pattern.findall(data)
12. print(phone_number)
8|Page
4.2 re.compile(pattern,repl,string):
Source Code:
1. import re
2. import numpy as np
3. numbers = np.array( [ '+8801838167090','+88018381dgg090','+876038167090','+8801988167
090'
4. ,'+9801838167090' ])
5. for i in numbers:
6. phone_pattern = re.compile(r'\+[8][8][0][1][3|5|7|8|9]\d{8}')
7. phone_number = phone_pattern.findall(i)
8. if phone_number == []:
9. print("invalid number")
10. else:
11. print(phone_number, "valid")
['+8801838167090'] valid
invalid number
invalid number
['+8801988167090'] valid
invalid number