├── .DS_Store
├── .idea
├── .gitignore
├── inspectionProfiles
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── pythonclass.iml
└── vcs.xml
├── __pycache__
├── database.cpython-38.pyc
├── database.cpython-39.pyc
├── validation.cpython-38.pyc
└── validation.cpython-39.pyc
├── appone.py
├── appone_updated.py
├── auth.py
├── calculator.py
├── data
└── user_record
│ ├── 1297388573.txt
│ ├── 3196779369.txt
│ ├── 3350850678.txt
│ ├── 5097616608.txt
│ └── 6277302096.txt
├── database.py
├── dictionary.py
├── function.py
├── hello.py
├── helloworld.py
├── lambda.py
└── validation.py
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyluz/pythonclass/adc7a72bc764836d0d06b5de039b4f2295f3442e/.DS_Store
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/pythonclass.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/__pycache__/database.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyluz/pythonclass/adc7a72bc764836d0d06b5de039b4f2295f3442e/__pycache__/database.cpython-38.pyc
--------------------------------------------------------------------------------
/__pycache__/database.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyluz/pythonclass/adc7a72bc764836d0d06b5de039b4f2295f3442e/__pycache__/database.cpython-39.pyc
--------------------------------------------------------------------------------
/__pycache__/validation.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyluz/pythonclass/adc7a72bc764836d0d06b5de039b4f2295f3442e/__pycache__/validation.cpython-38.pyc
--------------------------------------------------------------------------------
/__pycache__/validation.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xyluz/pythonclass/adc7a72bc764836d0d06b5de039b4f2295f3442e/__pycache__/validation.cpython-39.pyc
--------------------------------------------------------------------------------
/appone.py:
--------------------------------------------------------------------------------
1 | database_user = {
2 | 'Seyi':'passwordSeyi',
3 | 'Mike':'passwordMike',
4 | 'Love':'passwordLove'
5 | }
6 |
7 | def login():
8 | #login function here
9 | name = input("What is your name? \n")
10 | password = input("Your password? \n")
11 | if(name in database_user and password == database_user[name]):
12 | print("Welcome " + name)
13 | return True
14 | else:
15 | print("Password or Username Incorrect. Please try again")
16 | return False
17 |
18 |
19 | def bankOperations():
20 |
21 | print('These are the available options:')
22 | print('1. Withdrawal')
23 | print('2. Cash Deposit')
24 | print('3. Complaint')
25 | print('4. Logout')
26 |
27 | selectedOption = int(input('Please select an option:'))
28 |
29 | if(selectedOption == 1):
30 | print('you selected %s' % selectedOption)
31 | bankOperations()
32 |
33 | elif(selectedOption == 2):
34 | print('you selected %s' % selectedOption)
35 | bankOperations()
36 |
37 | elif(selectedOption == 3):
38 | print('you selected %s' % selectedOption)
39 | bankOperations()
40 |
41 | elif(selectedOption == 4):
42 | exit()
43 | else:
44 | print('Invalid Option selected, please try again')
45 |
46 |
47 | print("Welcome, what would you like to do?")
48 | print("1. Login")
49 | print("2. Register")
50 |
51 | actionSelect = int(input("Select an option \n"))
52 |
53 | if(actionSelect == 1):
54 | isLoginSuccessful = False
55 |
56 | while isLoginSuccessful == False:
57 | isLoginSuccessful = login()
58 |
59 | bankOperations()
60 |
61 | else:
62 | print('Login failed, username or password incorrect')
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/appone_updated.py:
--------------------------------------------------------------------------------
1 | def bankOperations():
2 |
3 | print('These are the available options:')
4 | print('1. Withdrawal')
5 | print('2. Cash Deposit')
6 | print('3. Complaint')
7 |
8 | selectedOption = int(input('Please select an option:'))
9 |
10 | if(selectedOption == 1):
11 | print('you selected %s' % selectedOption)
12 |
13 | elif(selectedOption == 2):
14 | print('you selected %s' % selectedOption)
15 |
16 | elif(selectedOption == 3):
17 | print('you selected %s' % selectedOption)
18 |
19 | else:
20 | print('Invalid Option selected, please try again')
21 |
22 | def withdrawal():
23 |
24 | amount = float(input("How much would you like to withdrawal?")
25 | print('processing..')
26 | print('take your cash')
27 |
28 |
29 |
30 |
31 | name = input("What is your name? \n")
32 |
33 | allowedUserDictionary = {
34 | 'Seyi':'passwordSeyi',
35 | 'Mike':'passwordMike',
36 | 'Love':'passwordLove'
37 | }
38 |
39 | if(name in allowedUserDictionary):
40 | password = input("Your password? \n")
41 |
42 | if(password == allowedUserDictionary[name]):
43 |
44 | print('Welcome %s' % name)
45 | bankOperations()
46 |
47 |
48 | else:
49 | print('Password Incorrect, please try again')
50 |
51 | else:
52 |
53 | print('Name not found, please try again')
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/auth.py:
--------------------------------------------------------------------------------
1 | # register
2 | # - first name, last name, password, email
3 | # - generate user account number
4 |
5 |
6 | # login
7 | # - account number & password
8 |
9 |
10 | # bank operations
11 |
12 | # Initializing the system
13 | import random
14 | import validation
15 | import database
16 | from getpass import getpass
17 |
18 | account_number_from_user = None
19 |
20 | def init():
21 | print("Welcome to bankPHP")
22 |
23 | have_account = int(input("Do you have account with us: 1 (yes) 2 (no) \n"))
24 |
25 | if have_account == 1:
26 |
27 | login()
28 |
29 | elif have_account == 2:
30 |
31 | register()
32 |
33 | else:
34 | print("You have selected invalid option")
35 | init()
36 |
37 |
38 | def login():
39 | print("********* Login ***********")
40 |
41 | global account_number_from_user
42 | account_number_from_user = input("What is your account number? \n")
43 |
44 | is_valid_account_number = validation.account_number_validation(account_number_from_user)
45 |
46 | if is_valid_account_number:
47 |
48 | password = getpass("What is your password \n")
49 |
50 | user = database.authenticated_user(account_number_from_user, password);
51 |
52 | if user:
53 | bank_operation(user)
54 |
55 | print('Invalid account or password')
56 | login()
57 |
58 | else:
59 | print("Account Number Invalid: check that you have up to 10 digits and only integers")
60 | init()
61 |
62 |
63 | def register():
64 | print("****** Register *******")
65 |
66 | email = input("What is your email address? \n")
67 | first_name = input("What is your first name? \n")
68 | last_name = input("What is your last name? \n")
69 | password = getpass("Create a password for yourself \n")
70 |
71 | account_number = generation_account_number()
72 |
73 | is_user_created = database.create(account_number, first_name, last_name, email, password)
74 |
75 | if is_user_created:
76 |
77 | print("Your Account Has been created")
78 | print(" == ==== ====== ===== ===")
79 | print("Your account number is: %d" % account_number)
80 | print("Make sure you keep it safe")
81 | print(" == ==== ====== ===== ===")
82 |
83 | login()
84 |
85 | else:
86 | print("Something went wrong, please try again")
87 | register()
88 |
89 |
90 | def bank_operation(user):
91 | print("Welcome %s %s " % (user[0], user[1]))
92 |
93 | selected_option = int(input("What would you like to do? (1) deposit (2) withdrawal (3) Logout (4) Exit \n"))
94 |
95 | if selected_option == 1:
96 |
97 | deposit_operation(user)
98 | elif selected_option == 2:
99 |
100 | withdrawal_operation()
101 | elif selected_option == 3:
102 |
103 | logout()
104 | elif selected_option == 4:
105 |
106 | exit()
107 | else:
108 |
109 | print("Invalid option selected")
110 | bank_operation(user)
111 |
112 |
113 | def withdrawal_operation():
114 | print("withdrawal")
115 | # get current balance
116 | # get amount to withdraw
117 | # check if current balance > withdraw balance
118 | # deduct withdrawn amount form current balance
119 | # display current balance
120 |
121 |
122 | def deposit_operation(user):
123 |
124 | current_balance = int(get_current_balance(user))
125 | amount_to_deposit = int(input("How much do you want to deposit? "))
126 | current_balance += amount_to_deposit
127 | set_current_balance(user, str(current_balance))
128 |
129 | if database.update(account_number_from_user, user):
130 | print("Your account balance is {}".format(current_balance))
131 | bank_operation(user)
132 |
133 | else:
134 | print("Transaction not successful")
135 | bank_operation(user)
136 |
137 | # get current balance
138 | # get amount to deposit
139 | # add deposited amount to current balance
140 | # display current balance
141 |
142 |
143 | def generation_account_number():
144 | return random.randrange(1111111111, 9999999999)
145 |
146 |
147 | def set_current_balance(user_details, balance):
148 | user_details[4] = balance
149 |
150 |
151 | def get_current_balance(user_details):
152 | return user_details[4]
153 |
154 |
155 | def logout():
156 | login()
157 |
158 |
159 | init()
160 |
--------------------------------------------------------------------------------
/calculator.py:
--------------------------------------------------------------------------------
1 | def operation(first,second,operator):
2 |
3 | if(operator == 1):
4 | return first + second
5 | if(operator == 2):
6 | return first - second
7 | if(operator == 3):
8 | return first / second
9 | if(operator == 4):
10 | return first * second
11 |
12 | return "invalid selection or input"
13 |
14 |
15 |
16 | print("Welcome to calculator.py, please enter 2 values to perform an operation")
17 | firstValue = float(input("What is the first value? \n"))
18 | secondValue = float(input("What is the second value? \n"))
19 |
20 | print("Available operations")
21 | print("1. add - add two numbers")
22 | print("2. sub - subtract two numbers")
23 | print("3. div - divide two numbers")
24 | print("4. mul - multiply two numbers")
25 |
26 | operator = int(input("What operation would you like to perform? \n"))
27 |
28 |
29 | print(operation(firstValue,secondValue,operator))
30 |
31 |
32 |
--------------------------------------------------------------------------------
/data/user_record/1297388573.txt:
--------------------------------------------------------------------------------
1 | Seyi_new,Onifed_new,seyi@new.com,passwordnew,0
--------------------------------------------------------------------------------
/data/user_record/3196779369.txt:
--------------------------------------------------------------------------------
1 | Seyi,Onifade,seyi@zuri.team,password,0
--------------------------------------------------------------------------------
/data/user_record/3350850678.txt:
--------------------------------------------------------------------------------
1 | M,U,s@m.com,password,0
--------------------------------------------------------------------------------
/data/user_record/5097616608.txt:
--------------------------------------------------------------------------------
1 | Mike,Alola,mike@zuri.team,mike,0
--------------------------------------------------------------------------------
/data/user_record/6277302096.txt:
--------------------------------------------------------------------------------
1 | Test,User,test@user.com,testuser,550
--------------------------------------------------------------------------------
/database.py:
--------------------------------------------------------------------------------
1 | # create record
2 | # update record
3 | # read record
4 | # delete record
5 | # CRUD
6 |
7 | # find user
8 |
9 | import os
10 | import validation
11 |
12 | user_db_path = "data/user_record/"
13 | auth_session_path = "data/auth_session"
14 |
15 |
16 | def create(user_account_number, first_name, last_name, email, password):
17 |
18 | # create a file
19 | # name of the file would be account_number.txt
20 | # add the user details to the file
21 | # return true
22 | # if saving to file fails, then deleted created file
23 |
24 | user_data = first_name + "," + last_name + "," + email + "," + password + "," + str(0)
25 |
26 | if does_account_number_exist(user_account_number):
27 |
28 | return False
29 |
30 | if does_email_exist(email):
31 | print("User already exists")
32 | return False
33 |
34 | completion_state = False
35 |
36 | try:
37 |
38 | f = open(user_db_path + str(user_account_number) + ".txt", "x")
39 |
40 | except FileExistsError:
41 |
42 | does_file_contain_data = read(user_db_path + str(user_account_number) + ".txt")
43 | if not does_file_contain_data:
44 | delete(user_account_number)
45 |
46 | else:
47 |
48 | f.write(str(user_data))
49 | completion_state = True
50 |
51 | finally:
52 |
53 | f.close()
54 | return completion_state
55 |
56 |
57 | def read(user_account_number):
58 |
59 | # find user with account number
60 | # fetch content of the file
61 | is_valid_account_number = validation.account_number_validation(user_account_number)
62 |
63 | try:
64 |
65 | if is_valid_account_number:
66 | f = open(user_db_path + str(user_account_number) + ".txt", "r")
67 | else:
68 | f = open(user_db_path + user_account_number, "r")
69 |
70 | except FileNotFoundError:
71 |
72 | print("User not found")
73 |
74 | except FileExistsError:
75 |
76 | print("User doesn't exist")
77 |
78 | except TypeError:
79 |
80 | print("Invalid account number format")
81 |
82 | else:
83 |
84 | return f.readline()
85 |
86 | return False
87 |
88 |
89 | def update(user_account_number, user_details):
90 |
91 | user = user_details[0] + "," + user_details[1] + "," + user_details[2] + "," + user_details[3] + "," + user_details[4]
92 |
93 | try:
94 | f = open(user_db_path + str(user_account_number) + ".txt", "w")
95 | f.write(user)
96 | return True
97 | except:
98 | return False
99 |
100 | def delete(user_account_number):
101 |
102 | # find user with account number
103 | # delete the user record (file)
104 | # return true
105 |
106 | is_delete_successful = False
107 |
108 | if os.path.exists(user_db_path + str(user_account_number) + ".txt"):
109 |
110 | try:
111 |
112 | os.remove(user_db_path + str(user_account_number) + ".txt")
113 | is_delete_successful = True
114 |
115 | except FileNotFoundError:
116 |
117 | print("User not found")
118 |
119 | finally:
120 |
121 | return is_delete_successful
122 |
123 |
124 | def does_email_exist(email):
125 |
126 | all_users = os.listdir(user_db_path)
127 |
128 | for user in all_users:
129 | user_list = str.split(read(user), ',')
130 | if email in user_list:
131 | return True
132 | return False
133 |
134 |
135 | def does_account_number_exist(account_number):
136 |
137 | all_users = os.listdir(user_db_path)
138 |
139 | for user in all_users:
140 |
141 | if user == str(account_number) + ".txt":
142 |
143 | return True
144 |
145 | return False
146 |
147 |
148 | def authenticated_user(account_number, password):
149 |
150 | if does_account_number_exist(account_number):
151 |
152 | user = str.split(read(account_number), ',')
153 |
154 | if password == user[3]:
155 | return user
156 |
157 | return False
158 |
159 |
160 |
--------------------------------------------------------------------------------
/dictionary.py:
--------------------------------------------------------------------------------
1 |
2 | # Dictionary
3 |
4 |
5 | #method 1
6 |
7 | dictionaryOne = {
8 | 'key1':'value1',
9 | 'key2':'value2',
10 | 'key3':'value3'
11 | }
12 |
13 | #method 2
14 |
15 | dictionaryTwo = {}
16 |
17 | dictionaryTwo['key4'] = 'value4'
18 | dictionaryTwo['key5'] = 'value5'
19 | dictionaryTwo['key6'] = 'value6'
20 |
21 |
22 | # del dictionaryTwo["key4"]
23 |
24 | # dictionaryOne.pop('key1')
25 |
26 | # print(dictionaryOne)
27 |
28 | #Dictionary Loop
29 |
30 | for key,value in dictionaryOne.items():
31 | print("I have " + key + " relating with " + value)
--------------------------------------------------------------------------------
/function.py:
--------------------------------------------------------------------------------
1 | def textRepeater(name):
2 | return name + ' called something inside a function \n'
3 |
4 |
5 | print(textRepeater('Seyi') * 4)
6 |
--------------------------------------------------------------------------------
/hello.py:
--------------------------------------------------------------------------------
1 | # Variable
2 |
3 | # Cup => anything you want, ranging from liquid to solid, to other things
4 |
5 | # cup = "Water" #water is the content inside the container cup. Our container is a variable.
6 |
7 | # print(cup)
8 |
9 | # cup = "Sand"
10 |
11 | # print(cup)
12 |
13 | # crate = ["Sand","Water",7,5.9,True] #list, array
14 |
15 | # print(crate[1])
16 |
17 | # crate.append('Mike')
18 |
19 | # print(crate[5])
20 |
21 | #Calculations
22 |
23 | #firstValue = 50 #camel casing, start with lowercase and subsequents words start with uppercase.
24 | #secondValue = 200
25 | #operator = +
26 |
27 | #operation - addition
28 |
29 | #result = firstValue + secondValue
30 |
31 | # thisIsTheResultOfAdditionOfFirstValueAndSecondValue = firstValue + secondValue;
32 |
33 | #print(result)
34 |
35 | #"String" "Word" 'Stiring'
36 |
37 | #Data type, String
38 |
39 | # string1 = "Mike"
40 | # string2 = "4.5"
41 | # string3 = '0'
42 | # string4 = 'truth'
43 | # string5 = "6"
44 |
45 | # print(string1 + ' is also saying the ' + string4)
46 |
47 |
48 | #Data type, Numbers
49 |
50 | # number1 = 4.5
51 | # number2 = 0
52 | # number3 = 5
53 | # number4 = -4
54 | # number5 = 139484747748484
55 |
56 |
57 | # print(number1 + number3)
58 |
59 | # print(number1 + string1)
60 |
61 | # age = 45
62 |
63 | # isStudentAction = True #yes
64 |
65 | # print(isStudentAction)
66 |
67 | # isGraduate = False #no
68 |
69 | # print(isGraduate)
70 |
71 | # if(age > 45):
72 | # print('yes')
73 |
74 | #Operators
75 |
76 | # firstValue = 14
77 | # secondValue = 3
78 |
79 | # #addition
80 | # print('addition--->')
81 | # print(firstValue + secondValue);
82 |
83 | #+ used for concatenation of strings
84 |
85 | #subtraction
86 | # print('subtraction--->')
87 | # print(firstValue - secondValue)
88 |
89 | # #multiplcation
90 | # print('multiplication--->')
91 | # print(firstValue * secondValue)
92 |
93 | # #division
94 | # print('division--->')
95 | # print(firstValue / secondValue)
96 |
97 | # assignment operator =
98 |
99 | # variable = 5;
100 |
101 | #comparison
102 | #isEqual
103 | # print(firstValue == secondValue) #comparison if 2 values are equal
104 |
105 | #isGreater
106 |
107 | # print(firstValue > secondValue)
108 |
109 | #isLess
110 |
111 | # print(firstValue < secondValue)
112 |
113 | #isGreaterorEqual
114 |
115 | # print(firstValue >= secondValue)
116 |
117 | #isLessOrEqual
118 |
119 | # print(firstValue <= secondValue)
120 |
121 |
122 | #reminder
123 |
124 | # print(firstValue % secondValue)
125 |
126 | # voice = "Shout "
127 |
128 | # print(voice * 5)
129 |
130 | # aList = [1,2,3,4,5,6]
131 |
132 | # print(aList * 3)
133 |
134 | # A = [1,2,3,4]
135 | # B = [5,6,7,8]
136 |
137 | # print(A + B)
138 |
139 | # age = 35
140 |
141 | # print(age)
142 |
143 | # age = age + 1
144 |
145 | # age /= 5
146 |
147 | # print(age)
148 |
149 | #String Formating
150 |
151 | # name = "Mike" #string - s
152 | # age = 55 #number - d
153 |
154 | # print("His name is %s and he is %d years old" % (name,age))
155 |
156 | # sampleList = ['mike','love','dove']
157 |
158 | # print("some text %s" % sampleList)
159 |
160 | #string methods
161 |
162 | # string = "I am a string"
163 | # string2 = "mike b"
164 | # string3 = "UPPERCASE STRING"
165 |
166 | # print(string[1:3])
167 |
168 | # print(string.upper())
169 | # print(string3.lower())
170 |
171 | # print(string[::-1])
172 |
173 | # print(string.startswith("P"))
174 |
175 | # print(string.endswith("shfsjfs"))
176 |
177 | #Conditionals
178 |
179 | #and / or
180 | #and - the two conditions must be true for the test to pass
181 | #or - only one is required to be true for the test to pass
182 | # age = 110000006
183 | # height = 4
184 |
185 | # if(age >= 18 and age < 1000000 and height >= 5):
186 |
187 | # print('Person can get on this ride')
188 |
189 | # elif(age < 18 or height < 5 ):
190 |
191 | # print('Person cannot get on this ride')
192 |
193 | # else:
194 |
195 | # print('Error, something went wrong with your inputs')
196 |
197 | # ==
198 |
199 | # alist = ['Mike','Live','Long']
200 | # name = 'Live'
201 |
202 | # if(name in alist):
203 | # print('Name Found!')
204 | # else:
205 | # print('Name not found!')
206 |
207 | #Loops
208 |
209 | # alist = [1,2,3,4,5,6]
210 |
211 | # for item in alist:
212 | # print(item)
213 |
214 | #break, or continue
215 |
216 | # for x in range(6):
217 | # if(x == 0):
218 | # continue
219 | # print(x)
220 |
221 | # count = 5
222 |
223 | # while count > 0:
224 | # print(count)
225 | # count -= 1
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
--------------------------------------------------------------------------------
/helloworld.py:
--------------------------------------------------------------------------------
1 | print('Hello World!')
--------------------------------------------------------------------------------
/lambda.py:
--------------------------------------------------------------------------------
1 | x = lambda a, b : a * b * c
2 |
3 |
4 | print(x(2, 6))
--------------------------------------------------------------------------------
/validation.py:
--------------------------------------------------------------------------------
1 | def account_number_validation(account_number):
2 |
3 | if account_number:
4 |
5 | try:
6 | int(account_number)
7 |
8 | if len(str(account_number)) == 10:
9 | return True
10 |
11 | except ValueError:
12 | return False
13 | except TypeError:
14 | return False
15 |
16 | return False
17 |
18 |
--------------------------------------------------------------------------------