Skip to content

Commit 7a89944

Browse files
committed
each challenge has been separated
1 parent 8a87595 commit 7a89944

Some content is hidden

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

45 files changed

+10927
-16
lines changed
+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Day 1 - 30DaysOfPython Challenge
1+
2+
# Day 1 - 30DaysOfPython Challenge
23

34
print(2 + 3) # addition(+)
45
print(3 - 1) # subtraction(-)
@@ -7,11 +8,13 @@
78
print(3 ** 2) # exponential(**)
89
print(3 % 2) # modulus(%)
910
print(3 // 2) # Floor division operator(//)
11+
1012
# Checking data types
13+
1114
print(type(10)) # Int
1215
print(type(3.14)) # Float
1316
print(type(1 + 3j)) # Complex
1417
print(type('Asabeneh')) # String
1518
print(type([1, 2, 3])) # List
16-
print(type({'name':'Asabeneh'})) #Dictionary
17-
print(type({9.8, 3.14, 2.7})) #Tuple
19+
print(type({'name':'Asabeneh'})) # Dictionary
20+
print(type({9.8, 3.14, 2.7})) # Tuple

02_Day/02_variables.md

+290
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
<div align="center">
2+
<h1> 30 Days Of Python: Day 2 - Variables</h1>
3+
<a class="header-badge" target="_blank" href="https://www.linkedin.com/in/asabeneh/">
4+
<img src="https://img.shields.io/badge/style--5eba00.svg?label=LinkedIn&logo=linkedin&style=social">
5+
</a>
6+
<a class="header-badge" target="_blank" href="https://twitter.com/Asabeneh">
7+
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/asabeneh?style=social">
8+
</a>
9+
10+
<sub>Author:
11+
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
12+
<small> First Edition: Nov 22 - Dec 22, 2019</small>
13+
</sub>
14+
</div>
15+
</div>
16+
17+
[<< Day 1](../01_Day/introduction.md) | [Day 3 >>](../03_Day/03_operators.md)
18+
19+
![30DaysOfPython](../images/[email protected])
20+
21+
- [📘 Day 2](#%f0%9f%93%98-day-2)
22+
- [Built in functions](#built-in-functions)
23+
- [Variables](#variables)
24+
- [Data Types](#data-types)
25+
- [Checking Data types and Casting](#checking-data-types-and-casting)
26+
- [Number](#number)
27+
- [💻 Exercises - Day 2](#%f0%9f%92%bb-exercises---day-2)
28+
29+
30+
31+
# 📘 Day 2
32+
33+
## Built in functions
34+
35+
In python we have lots of built in functions. Built-in functions are globally available for your use. 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/2/library/functions.html).
36+
37+
![Built in Functions](../images/builtin-functions.png)
38+
39+
Let's open the python shell and start using some of the most common built in functions.
40+
41+
![Built in functions](../images/builtin-functions_practice.png)
42+
43+
Let's practice more by using different built-in functions
44+
45+
![Help and Dir Built in Functions](/../images/help_and_dir_builtin.png)
46+
47+
As you can see from the above terminal, python has reserved words. We do not use reserved words to declare variables or functions. We will cover variables in the next section.
48+
49+
I believe, by now you are familiar with built-in functions. Let's do one more practice of built-in functions and we will move on to the next section
50+
51+
![Min Max Sum](../images/builtin-functional-final.png)
52+
53+
## Variables
54+
55+
Variables store data in a computer memory. Mnemonic variables are recommend to use in many programming languages. A variable refers to an a memory address in which a data is stored.
56+
Number at the beginning, special character, hyphen are not allowed. A variable can have a short name (like x,y,z) but a more descriptive name (firstname, lastname, age, country) is highly recommended .
57+
Python Variable Name Rules
58+
59+
- A variable name must start with a letter or the underscore character
60+
- A variable name cannot start with a number
61+
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and \_ )
62+
- Variable names are case-sensitive (firstname, Firstname, FirstName and FIRSTNAME are different variables)
63+
64+
Valid variable names
65+
66+
```shell
67+
firstname
68+
lastname
69+
age
70+
country
71+
city
72+
first_name
73+
last_name
74+
capital_city
75+
_if # if we want to use reserved word as a variable
76+
year_2019
77+
year2019
78+
current_year_2019
79+
num1
80+
num2
81+
```
82+
83+
Invalid variables names
84+
85+
```shell
86+
first-name
87+
num-1
88+
1num
89+
```
90+
91+
We will use standard python variable naming style which has been adopted by many python developers. The example below is an example of standard naming of variables, underscore when the variable name is long.
92+
93+
When we assign a certain data type to a variable is called variable declaration. For instance in the example below my first name is assigned to a variable first_name. The equal sign is an assignment operator. Assigning means storing data in the variable.
94+
95+
_Example:_
96+
97+
```py
98+
# Variables in Python
99+
100+
first_name = 'Asabeneh'
101+
last_name = 'Yetayeh'
102+
country = 'Finland'
103+
city = 'Helsinki'
104+
age = 250
105+
is_married = True
106+
skills = ['HTML', 'CSS', 'JS', 'React', 'Python']
107+
person_info = {
108+
'firstname':'Asabeneh',
109+
'lastname':'Yetayeh',
110+
'country':'Finland',
111+
'city':'Helsinki'
112+
}
113+
```
114+
115+
Let's use _print()_ and _len()_ built in functions. Print function will take multiple arguments. An argument is a value which we pass or put inside the function parenthesis, see the example below.
116+
117+
**Example:**
118+
119+
```py
120+
print('Hello, World!')
121+
print('Hello',',', 'World','!') # it can take multiple arguments
122+
print(len('Hello, World!')) # it takes only one argument
123+
```
124+
125+
Let's print and also find the length of the variables declared at the top:
126+
127+
**Example:**
128+
129+
```py
130+
# Printing the values stored in the variables
131+
132+
print('First name:', first_name)
133+
print('First name length:', len(first_name))
134+
print('Last name: ', last_name)
135+
print('Last name length: ', len(last_name))
136+
print('Country: ', country)
137+
print('City: ', city)
138+
print('Age: ', age)
139+
print('Married: ', is_married)
140+
print('Skills: ', skills)
141+
print('Person information: ', person_info)
142+
```
143+
144+
Variable can also be declared in one line:
145+
146+
**Example:**
147+
148+
```py
149+
first_name, last_name, country, age, is_married = 'Asabeneh', 'Yetayeh', 'Helsink', 250, True
150+
151+
print(first_name, last_name, country, age, is_married)
152+
print('First name:', first_name)
153+
print('Last name: ', last_name)
154+
print('Country: ', country)
155+
print('Age: ', age)
156+
print('Married: ', is_married)
157+
```
158+
159+
Getting user input using the _input()_ built-in function. Let's assign the data we get from a user into first_name and age variables.
160+
**Example:**
161+
162+
```py
163+
first_name = input('What is your name: ')
164+
age = input('How old are you? ')
165+
166+
print(first_name)
167+
print(age)
168+
```
169+
170+
## Data Types
171+
172+
There are several data types in python. To identify the data type we use the _type_ builtin function. I like you to focus understanding different data types very well. When it comes to programming it is all about data types. I introduced data types at the very beginning and it comes again, because every topic is related to data types. We will cover data types in more detail in their respective sections.
173+
174+
## Checking Data types and Casting
175+
176+
- Check Data types: To check the data type of a certain data type we use the _type_
177+
**Example:**
178+
179+
```py
180+
# Different python data types
181+
# Let's declare different data types
182+
183+
first_name = 'Asabeneh' # str
184+
last_name = 'Yetayeh' # str
185+
country = 'Finland' # str
186+
city= 'Helsinki' # str
187+
age = 250 # int, it is not my real age, don't worry about it
188+
189+
# Printing out types
190+
print(type('Asabeneh')) # str
191+
print(type(first_name)) # str
192+
print(type(10)) # int
193+
print(type(3.14)) # float
194+
print(type(1 + 1j)) # complex
195+
print(type(True)) # bool
196+
print(type([1, 2,3,4])) # list
197+
print(type({'name':'Asabeneh','age':250, 'is_married':250})) # dict
198+
print(type((1,2))) # tuple
199+
print(type(zip([1,2],[3,4]))) # set
200+
```
201+
202+
- Casting: Converting one data type to another data type. We use _int()_, _float()_, _str()_, _list_
203+
When we do arithmetic operations string numbers should be first converted to int or float if not it returns an error. If we concatenate a number with string, the number should be first converted to a string. We will talk about concatenation in String section.
204+
**Example:**
205+
206+
```py
207+
# int to float
208+
209+
num_int = 10
210+
print('num_int',num_int) # 10
211+
num_float = float(num_int)
212+
print('num_float:', num_float) # 10.0
213+
214+
# float to int
215+
216+
gravity = 9.81
217+
print(int(gravity)) # 9
218+
219+
# int to str
220+
num_int = 10
221+
print(num_int) # 10
222+
num_str = str(num_int)
223+
print(num_str) # '10'
224+
225+
# str to int
226+
num_str = '10.6'
227+
print('num_int', int(num_str)) # 10
228+
print('num_float', float(num_str)) # 10.6
229+
230+
# str to list
231+
first = 'Asabeneh'
232+
print(first_name)
233+
print(first_name) # 'Asabeneh'
234+
first_name_to_list = list(first_name)
235+
print(first_name_to_list) # ['A', 's', 'a', 'b', 'e', 'n', 'e', 'h']
236+
```
237+
238+
## Number
239+
240+
Numbers are python data types.
241+
242+
1. Integers: Integer(negative, zero and positive) numbers
243+
Example:
244+
... -3, -2, -1, 0, 1, 2, 3 ...
245+
246+
2. Floating Numbers(Decimal numbers)
247+
Example:
248+
... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ...
249+
250+
3. Complex Numbers
251+
Example:
252+
1 + j, 2 + 4j, 1 - 1j
253+
254+
## 💻 Exercises - Day 2
255+
256+
1. Inside 30DaysOfPython create a folder called day_2. Inside this folder create a file name called variables.py
257+
2. Writ a python comment saying 'Day 2: 30 Days of python programming'
258+
3. Declare a first name variable and assign a value to it
259+
4. Declare a last name variable and assign a value to it
260+
5. Declare a full name variable and assign a value to it
261+
6. Declare a country variable and assign a value to it
262+
7. Declare a city variable and assign a value to it
263+
8. Declare an age variable and assign a value to it
264+
9. Declare a year variable and assign a value to it
265+
10. Declare a variable is_married and assign a value to it
266+
11. Declare a variable is_true and assign a value to it
267+
12. Declare a variable is_light_on and assign a value to it
268+
13. Declare multiple variable on one line
269+
14. Check the data type of all your variables using type() built in function
270+
15. Using the _len()_ built-in function find the length of your first name
271+
16. Compare the length of your first name and your last name
272+
17. Declare 5 as num_one and 4 as num_two
273+
1. Add num_one and num_two and assign the value to a variable _total_
274+
2. Subtract num_two from num_one and assign the value to a variable _diff_
275+
3. Multiply num_two and num_one and assign the value to a variable _product_
276+
4. Divide num_one by num_two and assign the value to a variable _division_
277+
5. Use modulus division to find num_two divided by num_one and assign the value to a variable _remainder_
278+
6. Calculate num_one the power of num_two and assign the value to a variable _exp_
279+
7. Find floor division of num_one by num_two and assign the value to a variable _floor_division_
280+
18. The radius of a circle is 30 meters.
281+
1. Calculate the area of a circle and assign the value to a variable _area_of_circle_
282+
2. Calculate the circumference of a circle and assign the value to a variable _circum_of_circle_
283+
3. Take radius as user input and calculate the area.
284+
19. 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
285+
20. Run help('keywords') on python shell or in your file check the reserved words
286+
287+
288+
🎉 CONGRATULATIONS ! 🎉
289+
290+
[<< Day 1](../01_Day/introduction.md) | [Day 3 >>](../03_Day/03_operators.md)

day_2/variables.js 02_Day/variables.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
# Variables in Python
3+
24
first_name = 'Asabeneh'
35
last_name = 'Yetayeh'
46
country = 'Finland'
@@ -12,7 +14,9 @@
1214
'country':'Finland',
1315
'city':'Helsinki'
1416
}
17+
1518
# Printing the values stored in the variables
19+
1620
print('First name:', first_name)
1721
print('First name length:', len(first_name))
1822
print('Last name: ', last_name)
@@ -25,7 +29,9 @@
2529
print('Person information: ', person_info)
2630

2731
# Declaring multiple variables in one line
32+
2833
first_name, last_name, country, age, is_married = 'Asabeneh', 'Yetayeh', 'Helsink', 250, True
34+
2935
print(first_name, last_name, country, age, is_married)
3036
print('First name:', first_name)
3137
print('Last name: ', last_name)

0 commit comments

Comments
 (0)