Skip to content

Commit aeeb3c9

Browse files
authored
Merge branch 'master' into python-loops-grammatical-error
2 parents b0c402b + 4d7f24b commit aeeb3c9

File tree

126 files changed

+53125
-614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+53125
-614
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
github: [Asabeneh]
2+
thanks_dev:
3+
custom: []

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ flask_project/ven/lib
1717
numpy.ipynb
1818
.ipynb_checkpoints
1919
.vscode/
20+
*~
2021
test.py

01_Day_Introduction/helloworld.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Introduction
22
# Day 1 - 30DaysOfPython Challenge
33

4+
print("Hello World!") # print hello world
5+
46
print(2 + 3) # addition(+)
57
print(3 - 1) # subtraction(-)
68
print(2 * 3) # multiplication(*)
9+
print(3 + 2) # addition(+)
10+
print(3 - 2) # subtraction(-)
11+
print(3 * 2) # multiplication(*)
712
print(3 / 2) # division(/)
813
print(3 ** 2) # exponential(**)
914
print(3 % 2) # modulus(%)
@@ -19,3 +24,5 @@
1924
print(type({'name':'Asabeneh'})) # Dictionary
2025
print(type({9.8, 3.14, 2.7})) # Set
2126
print(type((9.8, 3.14, 2.7))) # Tuple
27+
print(type(3 == 3)) # Bool
28+
print(type(3 >= 3)) # Bool

02_Day_Variables_builtin_functions/02_variables_builtin_functions.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
## Built in functions
3535

36-
In Python we have lots of built-in functions. Built-in functions are globally available for your use that mean you can make use of the built-in functions without importing or configuring. Some of the most commonly used Python built-in functions are the following: _print()_, _len()_, _type()_, _int()_, _float()_, _str()_, _input()_, _list()_, _dict()_, _min()_, _max()_, _sum()_, _sorted()_, _open()_, _file()_, _help()_, and _dir()_. In the following table you will see an exhaustive list of Python built-in functions taken from [python documentation](https://docs.python.org/3.9/library/functions.html).
36+
In Python we have lots of built-in functions. Built-in functions are globally available for your use that mean you can make use of the built-in functions without importing or configuring. Some of the most commonly used Python built-in functions are the following: _print()_, _len()_, _type()_, _int()_, _float()_, _str()_, _input()_, _list()_, _dict()_, _min()_, _max()_, _sum()_, _sorted()_, _open()_, _file()_, _help()_, and _dir()_. In the following table you will see an exhaustive list of Python built-in functions taken from [python documentation](https://docs.python.org/3/library/functions.html).
3737

3838
![Built-in Functions](../images/builtin-functions.png)
3939

@@ -63,7 +63,7 @@ Python Variable Name Rules
6363
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and \_ )
6464
- Variable names are case-sensitive (firstname, Firstname, FirstName and FIRSTNAME) are different variables)
6565

66-
Let us se valid variable names
66+
Here are some example of valid variable names:
6767

6868
```shell
6969
firstname
@@ -180,7 +180,7 @@ There are several data types in Python. To identify the data type we use the _ty
180180
## Checking Data types and Casting
181181

182182
- Check Data types: To check the data type of certain data/variable we use the _type_
183-
**Example:**
183+
**Examples:**
184184

185185
```py
186186
# Different python data types
@@ -193,22 +193,22 @@ city= 'Helsinki' # str
193193
age = 250 # int, it is not my real age, don't worry about it
194194

195195
# Printing out types
196-
print(type('Asabeneh')) # str
197-
print(type(first_name)) # str
198-
print(type(10)) # int
199-
print(type(3.14)) # float
200-
print(type(1 + 1j)) # complex
201-
print(type(True)) # bool
202-
print(type([1, 2, 3, 4])) # list
203-
print(type({'name':'Asabeneh','age':250, 'is_married':250})) # dict
204-
print(type((1,2))) # tuple
205-
print(type(zip([1,2],[3,4]))) # set
196+
print(type('Asabeneh')) # str
197+
print(type(first_name)) # str
198+
print(type(10)) # int
199+
print(type(3.14)) # float
200+
print(type(1 + 1j)) # complex
201+
print(type(True)) # bool
202+
print(type([1, 2, 3, 4])) # list
203+
print(type({'name':'Asabeneh'})) # dict
204+
print(type((1,2))) # tuple
205+
print(type(zip([1,2],[3,4]))) # zip
206206
```
207207

208208
- Casting: Converting one data type to another data type. We use _int()_, _float()_, _str()_, _list_, _set_
209209
When we do arithmetic operations string numbers should be first converted to int or float otherwise it will return an error. If we concatenate a number with a string, the number should be first converted to a string. We will talk about concatenation in String section.
210210

211-
**Example:**
211+
**Examples:**
212212

213213
```py
214214
# int to float
@@ -229,8 +229,12 @@ print(num_str) # '10'
229229

230230
# str to int or float
231231
num_str = '10.6'
232+
num_float = float(num_str) # Convert the string to a float first
233+
num_int = int(num_float) # Then convert the float to an integer
232234
print('num_int', int(num_str)) # 10
233235
print('num_float', float(num_str)) # 10.6
236+
num_int = int(num_float)
237+
print('num_int', int(num_int)) # 10
234238

235239
# str to list
236240
first_name = 'Asabeneh'
@@ -278,22 +282,22 @@ Number data types in Python:
278282
### Exercises: Level 2
279283

280284
1. Check the data type of all your variables using type() built-in function
281-
1. Using the _len()_ built-in function, find the length of your first name
282-
1. Compare the length of your first name and your last name
283-
1. Declare 5 as num_one and 4 as num_two
284-
1. Add num_one and num_two and assign the value to a variable total
285-
2. Subtract num_two from num_one and assign the value to a variable diff
286-
3. Multiply num_two and num_one and assign the value to a variable product
287-
4. Divide num_one by num_two and assign the value to a variable division
288-
5. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder
289-
6. Calculate num_one to the power of num_two and assign the value to a variable exp
290-
7. Find floor division of num_one by num_two and assign the value to a variable floor_division
291-
1. The radius of a circle is 30 meters.
285+
2. Using the _len()_ built-in function, find the length of your first name
286+
3. Compare the length of your first name and your last name
287+
4. Declare 5 as num_one and 4 as num_two
288+
5. Add num_one and num_two and assign the value to a variable total
289+
6. Subtract num_two from num_one and assign the value to a variable diff
290+
7. Multiply num_two and num_one and assign the value to a variable product
291+
8. Divide num_one by num_two and assign the value to a variable division
292+
9. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder
293+
10. Calculate num_one to the power of num_two and assign the value to a variable exp
294+
11. Find floor division of num_one by num_two and assign the value to a variable floor_division
295+
12. The radius of a circle is 30 meters.
292296
1. Calculate the area of a circle and assign the value to a variable name of _area_of_circle_
293297
2. Calculate the circumference of a circle and assign the value to a variable name of _circum_of_circle_
294298
3. Take radius as user input and calculate the area.
295-
1. Use the built-in input function to get first name, last name, country and age from a user and store the value to their corresponding variable names
296-
1. Run help('keywords') in Python shell or in your file to check for the Python reserved words or keywords
299+
13. Use the built-in input function to get first name, last name, country and age from a user and store the value to their corresponding variable names
300+
14. Run help('keywords') in Python shell or in your file to check for the Python reserved words or keywords
297301

298302
🎉 CONGRATULATIONS ! 🎉
299303

02_Day_Variables_builtin_functions/variables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@
3737
print('Last name: ', last_name)
3838
print('Country: ', country)
3939
print('Age: ', age)
40-
print('Married: ', is_married)
40+
print('Married: ', is_married)
41+

03_Day_Operators/03_operators.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ print('Division: ', 7 / 2) # 3.5
7575
print('Division without the remainder: ', 7 // 2) # 3, gives without the floating number or without the remaining
7676
print ('Division without the remainder: ',7 // 3) # 2
7777
print('Modulus: ', 3 % 2) # 1, Gives the remainder
78-
print('Exponentiation: ', 2 ** 3) # 9 it means 2 * 2 * 2
78+
print('Exponentiation: ', 2 ** 3) # 8 it means 2 * 2 * 2
7979
```
8080

8181
**Example:Floats**
@@ -121,7 +121,7 @@ print('a * b = ', product)
121121
print('a / b = ', division)
122122
print('a % b = ', remainder)
123123
print('a // b = ', floor_division)
124-
print('a ** b = ', exponentiation)
124+
print('a ** b = ', exponential)
125125
```
126126

127127
**Example:**
@@ -148,7 +148,7 @@ print('division: ', div)
148148
print('remainder: ', remainder)
149149
```
150150

151-
Let us start start connecting the dots and start making use of what we already know to calculate (area, volume,density, weight, perimeter, distance, force).
151+
Let us start connecting the dots and start making use of what we already know to calculate (area, volume,density, weight, perimeter, distance, force).
152152

153153
**Example:**
154154

@@ -174,6 +174,7 @@ print(weight, 'N') # Adding unit to the weight
174174
mass = 75 # in Kg
175175
volume = 0.075 # in cubic meter
176176
density = mass / volume # 1000 Kg/m^3
177+
print(density, 'Kg/m^3') # Adding unit to the density
177178

178179
```
179180

@@ -213,13 +214,13 @@ In addition to the above comparison operator Python uses:
213214
- _is_: Returns true if both variables are the same object(x is y)
214215
- _is not_: Returns true if both variables are not the same object(x is not y)
215216
- _in_: Returns True if the queried list contains a certain item(x in y)
216-
- _not in_: Returns True if the queried list doesn't have a certain item(x in y)
217+
- _not in_: Returns True if the queried list doesn't have a certain item(x not in y)
217218

218219
```py
219220
print('1 is 1', 1 is 1) # True - because the data values are the same
220221
print('1 is not 2', 1 is not 2) # True - because 1 is not 2
221222
print('A in Asabeneh', 'A' in 'Asabeneh') # True - A found in the string
222-
print('B in Asabeneh', 'B' in 'Asabeneh') # False - there is no uppercase B
223+
print('B not in Asabeneh', 'B' in 'Asabeneh') # False - there is no uppercase B
223224
print('coding' in 'coding for all') # True - because coding for all has the word coding
224225
print('a in an:', 'a' in 'an') # True
225226
print('4 is 2 ** 2:', 4 is 2 ** 2) # True
@@ -287,7 +288,7 @@ The perimeter of the triangle is 12
287288
18. Check if the floor division of 7 by 3 is equal to the int converted value of 2.7.
288289
19. Check if type of '10' is equal to type of 10
289290
20. Check if int('9.8') is equal to 10
290-
21. Writ a script that prompts the user to enter hours and rate per hour. Calculate pay of the person?
291+
21. Write a script that prompts the user to enter hours and rate per hour. Calculate pay of the person?
291292

292293
```py
293294
Enter hours: 40

03_Day_Operators/day-3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
print('Division without the remainder: ', 7 // 2) # gives without the floating number or without the remaining
1111
print('Modulus: ', 3 % 2) # Gives the remainder
1212
print ('Division without the remainder: ', 7 // 3)
13-
print('Exponential: ', 3 ** 2) # it means 3 * 3
13+
print('Exponential: ', 2 ** 3) # 8 it means 2 * 2 * 2
1414

1515
# Floating numbers
1616
print('Floating Number,PI', 3.14)

04_Day_Strings/04_strings.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ print(len(full_name)) # 16
9292
In Python and other programming languages \ followed by a character is an escape sequence. Let us see the most common escape characters:
9393

9494
- \n: new line
95-
- \t: Tab means(8 spaces)
95+
- \t: Tab means(8 spaces)
9696
- \\\\: Back slash
9797
- \\': Single quote (')
9898
- \\": Double quote (")
@@ -101,18 +101,18 @@ Now, let us see the use of the above escape sequences with examples.
101101

102102
```py
103103
print('I hope everyone is enjoying the Python Challenge.\nAre you ?') # line break
104-
print('Days\tTopics\tExercises') # adding tab space or 4 spaces
105-
print('Day 1\t3\t5')
106-
print('Day 2\t3\t5')
107-
print('Day 3\t3\t5')
108-
print('Day 4\t3\t5')
104+
print('Days\tTopics\tExercises') # adding tab space or 4 spaces
105+
print('Day 1\t5\t5')
106+
print('Day 2\t6\t20')
107+
print('Day 3\t5\t23')
108+
print('Day 4\t1\t35')
109109
print('This is a backslash symbol (\\)') # To write a backslash
110110
print('In every programming language it starts with \"Hello, World!\"') # to write a double quote inside a single quote
111111

112112
# output
113113
I hope every one is enjoying the Python Challenge.
114114
Are you ?
115-
Days Topics Exercises
115+
Days Topics Exercises
116116
Day 1 5 5
117117
Day 2 6 20
118118
Day 3 5 23
@@ -154,7 +154,7 @@ print(formated_string) # "The following are python libraries:['Django', 'Flask',
154154

155155
#### New Style String Formatting (str.format)
156156

157-
This formatting is introduced in Python version 3.
157+
This format was introduced in Python version 3.
158158

159159
```py
160160

@@ -328,16 +328,16 @@ print(challenge.expandtabs(10)) # 'thirty days of python'
328328

329329
```py
330330
challenge = 'thirty days of python'
331-
print(challenge.find('y')) # 16
332-
print(challenge.find('th')) # 17
331+
print(challenge.find('y')) # 5
332+
print(challenge.find('th')) # 0
333333
```
334334

335335
- rfind(): Returns the index of the last occurrence of a substring, if not found returns -1
336336

337337
```py
338338
challenge = 'thirty days of python'
339-
print(challenge.rfind('y')) # 5
340-
print(challenge.rfind('th')) # 1
339+
print(challenge.rfind('y')) # 16
340+
print(challenge.rfind('th')) # 17
341341
```
342342

343343
- format(): formats string into a nicer output
@@ -349,7 +349,7 @@ last_name = 'Yetayeh'
349349
age = 250
350350
job = 'teacher'
351351
country = 'Finland'
352-
sentence = 'I am {} {}. I am a {}. I am {} years old. I live in {}.'.format(first_name, last_name, age, job, country)
352+
sentence = 'I am {} {}. I am a {}. I am {} years old. I live in {}.'.format(first_name, last_name, job, age, country)
353353
print(sentence) # I am Asabeneh Yetayeh. I am 250 years old. I am a teacher. I live in Finland.
354354

355355
radius = 10
@@ -373,8 +373,9 @@ print(challenge.index(sub_string, 9)) # error
373373
```py
374374
challenge = 'thirty days of python'
375375
sub_string = 'da'
376-
print(challenge.rindex(sub_string)) # 8
376+
print(challenge.rindex(sub_string)) # 7
377377
print(challenge.rindex(sub_string, 9)) # error
378+
print(challenge.rindex('on', 8)) # 19
378379
```
379380

380381
- isalnum(): Checks alphanumeric character
@@ -412,7 +413,7 @@ print(challenge.isdecimal()) # False
412413
challenge = '123'
413414
print(challenge.isdecimal()) # True
414415
challenge = '\u00B2'
415-
print(challenge.isdigit()) # False
416+
print(challenge.isdigit()) # True
416417
challenge = '12 3'
417418
print(challenge.isdecimal()) # False, space not allowed
418419
```
@@ -544,7 +545,7 @@ print(challenge.startswith('thirty')) # False
544545
9. Cut(slice) out the first word of _Coding For All_ string.
545546
10. Check if _Coding For All_ string contains a word Coding using the method index, find or other methods.
546547
11. Replace the word coding in the string 'Coding For All' to Python.
547-
12. Change Python for Everyone to Python for All using the replace method or other methods.
548+
12. Change "Python for Everyone" to "Python for All" using the replace method or other methods.
548549
13. Split the string 'Coding For All' using space as the separator (split()) .
549550
14. "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon" split the string at the comma.
550551
15. What is the character at index 0 in the string _Coding For All_.
@@ -560,7 +561,7 @@ print(challenge.startswith('thirty')) # False
560561
25. Slice out the phrase 'because because because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction'
561562
26. Find the position of the first occurrence of the word 'because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction'
562563
27. Slice out the phrase 'because because because' in the following sentence: 'You cannot end a sentence with because because because is a conjunction'
563-
28. Does '\'Coding For All' start with a substring _Coding_?
564+
28. Does 'Coding For All' start with a substring _Coding_?
564565
29. Does 'Coding For All' end with a substring _coding_?
565566
30. '   Coding For All      '  , remove the left and right trailing spaces in the given string.
566567
31. Which one of the following variables return True when we use the method isidentifier():

04_Day_Strings/day_4.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
print(len(first_name)) # 8
3131
print(len(last_name)) # 7
3232
print(len(first_name) > len(last_name)) # True
33-
print(len(full_name)) # 15
33+
print(len(full_name)) # 16
3434

3535
#### Unpacking characters
3636
language = 'Python'
@@ -153,7 +153,7 @@
153153
# isalpha(): Checks if all characters are alphabets
154154

155155
challenge = 'thirty days of python'
156-
print(challenge.isalpha()) # True
156+
print(challenge.isalpha()) # False
157157
num = '123'
158158
print(num.isalpha()) # False
159159

@@ -168,7 +168,7 @@
168168
challenge = 'Thirty'
169169
print(challenge.isdigit()) # False
170170
challenge = '30'
171-
print(challenge.digit()) # True
171+
print(challenge.isdigit()) # True
172172

173173
# isdecimal():Checks decimal characters
174174

@@ -210,13 +210,13 @@
210210
# join(): Returns a concatenated string
211211

212212
web_tech = ['HTML', 'CSS', 'JavaScript', 'React']
213-
result = '#, '.join(web_tech)
214-
print(result) # 'HTML# CSS# JavaScript# React'
213+
result = '# '.join(web_tech)
214+
print(result) # 'HTML# CSS# JavaScript# React'
215215

216216
# strip(): Removes both leading and trailing characters
217217

218218
challenge = ' thirty days of python '
219-
print(challenge.strip('y')) # 5
219+
print(challenge.strip()) # 'thirty days of python'
220220

221221
# replace(): Replaces substring inside
222222

0 commit comments

Comments
 (0)