You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Casting: Converting one data type to another data type. We use _int()_, _float()_, _str()_, _list_, _set_
209
209
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.
210
210
211
-
**Example:**
211
+
**Examples:**
212
212
213
213
```py
214
214
# int to float
@@ -229,8 +229,10 @@ print(num_str) # '10'
229
229
230
230
# str to int or float
231
231
num_str ='10.6'
232
-
print('num_int', int(num_str)) # 10
232
+
num_float =float(num_str)
233
233
print('num_float', float(num_str)) # 10.6
234
+
num_int =int(num_float)
235
+
print('num_int', int(num_int)) # 10
234
236
235
237
# str to list
236
238
first_name ='Asabeneh'
@@ -281,13 +283,13 @@ Number data types in Python:
281
283
1. Using the _len()_ built-in function, find the length of your first name
282
284
1. Compare the length of your first name and your last name
283
285
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
286
+
1. Add num_one and num_two and assign the value to a variable total
287
+
1. Subtract num_two from num_one and assign the value to a variable diff
288
+
1. Multiply num_two and num_one and assign the value to a variable product
289
+
1. Divide num_one by num_two and assign the value to a variable division
290
+
1. Use modulus division to find num_two divided by num_one and assign the value to a variable remainder
291
+
1. Calculate num_one to the power of num_two and assign the value to a variable exp
292
+
1. Find floor division of num_one by num_two and assign the value to a variable floor_division
291
293
1. The radius of a circle is 30 meters.
292
294
1. Calculate the area of a circle and assign the value to a variable name of _area_of_circle_
293
295
2. Calculate the circumference of a circle and assign the value to a variable name of _circum_of_circle_
It returns the the symmetric difference between two sets. It means that it returns a set that contains all items from both sets, except items that are present in both sets, mathematically: (A\B) ∪ (B\A)
346
+
It returns the symmetric difference between two sets. It means that it returns a set that contains all items from both sets, except items that are present in both sets, mathematically: (A\B) ∪ (B\A)
347
347
348
348
```py
349
349
# syntax
@@ -380,7 +380,7 @@ st2.isdisjoint(st1) # False
380
380
381
381
```py
382
382
even_numbers = {0, 2, 4 ,6, 8}
383
-
even_numbers= {1, 3, 5, 7, 9}
383
+
odd_numbers= {1, 3, 5, 7, 9}
384
384
even_numbers.isdisjoint(odd_numbers) # True, because no common item
Copy file name to clipboardExpand all lines: 09_Day_Conditionals/09_conditionals.md
+26-17Lines changed: 26 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,8 @@
29
29
-[If and Or Logical Operators](#if-and-or-logical-operators)
30
30
-[💻 Exercises: Day 9](#-exercises-day-9)
31
31
-[Exercises: Level 1](#exercises-level-1)
32
+
-[Exercises: Level 2](#exercises-level-2)
33
+
-[Exercises: Level 3](#exercises-level-3)
32
34
33
35
# 📘 Day 9
34
36
@@ -72,7 +74,7 @@ else:
72
74
this part of code runs for false conditions
73
75
```
74
76
75
-
**Example:**
77
+
**Example:**
76
78
77
79
```py
78
80
a = 3
@@ -82,7 +84,7 @@ else:
82
84
print('A is a positive number')
83
85
```
84
86
85
-
The condition above proves false, therefore the else block was executed. How about if our condition is more than two? We could use _ elif_.
87
+
The condition above proves false, therefore the else block was executed. How about if our condition is more than two? We could use _elif_.
86
88
87
89
### If Elif Else
88
90
@@ -99,7 +101,7 @@ else:
99
101
100
102
```
101
103
102
-
**Example:**
104
+
**Example:**
103
105
104
106
```py
105
107
a = 0
@@ -118,7 +120,7 @@ else:
118
120
code if condition else code
119
121
```
120
122
121
-
**Example:**
123
+
**Example:**
122
124
123
125
```py
124
126
a = 3
@@ -137,7 +139,7 @@ if condition:
137
139
code
138
140
```
139
141
140
-
**Example:**
142
+
**Example:**
141
143
142
144
```py
143
145
a = 0
@@ -163,7 +165,7 @@ if condition and condition:
163
165
code
164
166
```
165
167
166
-
**Example:**
168
+
**Example:**
167
169
168
170
```py
169
171
a = 0
@@ -185,7 +187,7 @@ if condition or condition:
185
187
code
186
188
```
187
189
188
-
**Example:**
190
+
**Example:**
189
191
190
192
```py
191
193
user = 'James'
@@ -202,53 +204,60 @@ else:
202
204
203
205
### Exercises: Level 1
204
206
205
-
1. Get user input using input(“Enter your age: ”). If user is18or older, give feedback: You are old enough to drive. If below 18 give feedback to wait for the missing amount of years. Output:
207
+
1. Get user input using input(“Enter your age: ”). If user is18or older, give feedback: You are old enough to drive. If below 18 give feedback to wait for the missing amount of years. Output:
208
+
206
209
```sh
207
210
Enter your age: 30
208
211
You are old enough to learn to drive.
209
212
Output:
210
213
Enter your age: 15
211
214
You need 3 more years to learn to drive.
212
215
```
213
-
2. Compare the values of my_age and your_age using if … else. Who is older (me or you)? Use input(“Enter your age: ”) to get the age asinput. You can use a nested condition to print'year'for1 year difference in age, 'years'for bigger differences, and a custom text if my_age = your_age. Output:
216
+
217
+
2. Compare the values of my_age and your_age using if … else. Who is older (me or you)? Use input(“Enter your age: ”) to get the age asinput. You can use a nested condition to print'year'for1 year difference in age, 'years'for bigger differences, and a custom text if my_age = your_age. Output:
218
+
214
219
```sh
215
220
Enter your age: 30
216
221
You are 5 years older than me.
217
222
```
218
-
3. Get two numbers from the user using input prompt. If a is greater than b return a is greater than b, if a is less b return a is smaller than b, else a is equal to b. Output:
223
+
224
+
3. Get two numbers from the user using input prompt. If a is greater than b return a is greater than b, if a is less b return a is smaller than b, else a is equal to b. Output:
219
225
220
226
```sh
221
227
Enter number one: 4
222
228
Enter number two: 3
223
229
4is greater than 3
224
230
```
225
231
226
-
### Exercises: Level 2
232
+
### Exercises: Level 2
227
233
228
234
1. Write a code which gives grade to students according to theirs scores:
229
-
235
+
230
236
```sh
231
237
80-100, A
232
238
70-89, B
233
239
60-69, C
234
240
50-59, D
235
241
0-49, F
236
242
```
237
-
1. Check if the season is Autumn, Winter, Spring or Summer. If the user inputis:
243
+
244
+
1. Check if the season is Autumn, Winter, Spring or Summer. If the user inputis:
238
245
September, October or November, the season is Autumn.
239
246
December, January or February, the season is Winter.
240
247
March, April or May, the season is Spring
241
248
June, July or August, the season is Summer
242
-
2. The following list contains some fruits:
249
+
2. The following list contains some fruits:
250
+
243
251
```sh
244
252
fruits = ['banana', 'orange', 'mango', 'lemon']
245
253
```
246
-
If a fruit doesn't exist in the list add the fruit to the list and print the modified list. If the fruit exists print('That fruit already exist in the list')
247
254
248
-
### Exercises: Level 3
255
+
If a fruit doesn't exist in the list add the fruit to the list and print the modified list. If the fruit exists print('That fruit already exist in the list')
256
+
257
+
### Exercises: Level 3
249
258
250
259
1. Here we have a person dictionary. Feel free to modify it!
Copy file name to clipboardExpand all lines: 11_Day_Functions/11_functions.md
+12-10Lines changed: 12 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,7 @@
31
31
-[Arbitrary Number of Arguments](#arbitrary-number-of-arguments)
32
32
-[Default and Arbitrary Number of Parameters in Functions](#default-and-arbitrary-number-of-parameters-in-functions)
33
33
-[Function as a Parameter of Another Function](#function-as-a-parameter-of-another-function)
34
+
-[Testimony](#testimony)
34
35
-[💻 Exercises: Day 11](#-exercises-day-11)
35
36
-[Exercises: Level 1](#exercises-level-1)
36
37
-[Exercises: Level 2](#exercises-level-2)
@@ -48,7 +49,7 @@ A function is a reusable block of code or programming statements designed to per
48
49
49
50
### Declaring and Calling a Function
50
51
51
-
When we make a function, we call it declaring a function. When we start using the it, we call it *calling* or *invoking* a function. Function can be declared with or without parameters.
52
+
When we make a function, we call it declaring a function. When we start using the it, we call it _calling_ or _invoking_ a function. Function can be declared with or without parameters.
🌕 You achieved quite a lot so far. Keep going! You have just completed day 11 challenges and you are 11 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.
375
376
376
377
## Testimony
377
-
Now it is time to express your thoughts about the Author and 30DaysOfPython. You can leave your testimonial on this [link](https://testimonify.herokuapp.com/)
378
+
379
+
Now it is time to express your thoughts about the Author and 30DaysOfPython. You can leave your testimonial on this [link](https://testimonial-s3sw.onrender.com/)
0 commit comments