Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S bgh00 patch 5 #501

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 29 additions & 13 deletions 01_Day_Introduction/helloworld.py
@@ -1,21 +1,37 @@
# Introduction
# Day 1 - 30DaysOfPython Challenge

print(2 + 3) # addition(+)
print(3 - 1) # subtraction(-)
print(2 * 3) # multiplication(*)
print(3 / 2) # division(/)
print(3 ** 2) # exponential(**)
print(3 % 2) # modulus(%)
print(3 // 2) # Floor division operator(//)
print(3 + 4) # addition(+)
print(3 - 4) # subtraction(-)
print(3 * 4) # multiplication(*)
print(3 / 4) # division(/)
print(3 ** 4) # exponential(**)
print(3 % 4) # modulus(%)
print(3 // 4) # Floor division operator(//)

# Checking data types

print(type(10)) # Int
print(type(9.8)) #Float
print(type(3.14)) # Float
print(type(1 + 3j)) # Complex
print(type('Asabeneh')) # String
print(type([1, 2, 3])) # List
print(type({'name':'Asabeneh'})) # Dictionary
print(type({9.8, 3.14, 2.7})) # Set
print(type((9.8, 3.14, 2.7))) # Tuple
print(type(4 - 4j)) # Complex
print(type['Asabeneh', 'Python', 'Finland']) # List
print(type("Sara")) # String
print(type("Bgh")) #String
print(type("Iran")) #String

# Level 3
print(type(13)) #Int
print(type(13.13)) #Float
print(type(13 + 13j)) #Complex
print(type("Sara")) #String
print(type(True)) #Bool
print(type([1, 2, 3])) #List
print(type({'first_name' : 'Sara', 'last_name' : 'Bgh', 'age' : 22})) #Dict
print(type(("sara", "bgh"))) #tuple
print(type({1, 2, 3})) #set

import math as mt
euc_dis = mt.sqrt(((8 - 3) ** 2) + ((10 - 2) ** 2))
print(euc_dis)

115 changes: 115 additions & 0 deletions 05_Day_Lists/05_lists.md
Expand Up @@ -584,5 +584,120 @@ ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]
1. ['China', 'Russia', 'USA', 'Finland', 'Sweden', 'Norway', 'Denmark']. Unpack the first three countries and the rest as scandic countries.

🎉 CONGRATULATIONS ! 🎉
## 💻 Exercises: Day 5

### Exercises: Level 1

1. Declare an empty list
empty_list = ()
2. Declare a list with more than 5 items
list = [A, B, C, D, E, F, G]
3. Find the length of your list
print('number of items on the list:', len(list))
4. Get the first item, the middle item and the last item of the list
print(list[0])
print(list[1])
print(list[-1])
5. Declare a list called mixed_data_types, put your(name, age, height, marital status, address)
mixed_data_types = ['Sara', 250, 310.5, False, 'Iran') # LOL
6. Declare a list variable named it_companies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon.
it_companies = ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon']
7. Print the list using _print()_
print(it_companies)
8. Print the number of companies in the list
print(len(it_companies))
9. Print the first, middle and last company
print(it_companies[0])
print(it_companies[2])
print(it_companies[-1])
10. Print the list after modifying one of the companies
it_companies[2] = 'X'
print(it_companies)
11. Add an IT company to it_companies
it_companies.append('nvidia')
12. Insert an IT company in the middle of the companies list
it_companies.insert(2, 'hp')
13. Change one of the it_companies names to uppercase (IBM excluded!)
it_companies[0] = it_companies[0].upper()
14. Join the it_companies with a string '#;  '
new_list = it_companies.append("#;  ")
15. Check if a certain company exists in the it_companies list.
is_true = 'IBM' in it_companies
print(is_true)
16. Sort the list using sort() method
it_companies.sort()
17. Reverse the list in descending order using reverse() method
it_companies.reverse()
18. Slice out the first 3 companies from the list
it_companies[0:3]
19. Slice out the last 3 companies from the list
it_companies[-3:]
20. Slice out the middle IT company or companies from the list
it_companies[1:-1]
21. Remove the first IT company from the list
it_companies.pop(0)
22. Remove the middle IT company or companies from the list
it_companies.del(1:-1)
23. Remove the last IT company from the list
it_comapnies.pop()
24. Remove all IT companies from the list
it_companies.clear()
25. Destroy the IT companies list
del it_companies
26. Join the following lists:

```py
front_end = ['HTML', 'CSS', 'JS', 'React', 'Redux']
back_end = ['Node','Express', 'MongoDB']
```
joined = front_end + back_end

27. After joining the lists in question 26. Copy the joined list and assign it to a variable full_stack. Then insert Python and SQL after Redux.
full_stack = joined.copy()
exra = ['Python, 'SQL']
full_stack.extend(extra)

### Exercises: Level 2

1. The following is a list of 10 students ages:

```sh
ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]
```
# Sort the list and find the min and max age'
ages.sort()
print(ages)
print(min(ages), max(ages))
# Add the min age and the max age again to the list
new = [min(ages), max(ages)]
ages = ages + new
print(ages)
# Find the median age (one middle item or two middle items divided by two)
# Find the average age (sum of all items divided by their number )
ave = sum(ages) / len(ages)
print(ave)
# Find the range of the ages (max minus min)
ra = max(ages) - min(ages)
print(ra)
# Compare the value of (min - average) and (max - average), use _abs()_ method
d = abs(min(ages) - ave)
e = (max(ages) - ave)
comp = d > e
print(comp)
print(median(ages))

1. Find the middle country(ies) in the [countries list](https://github.com/Asabeneh/30-Days-Of-Python/tree/master/data/countries.py)
countries[1:-1]
1. Divide the countries list into two equal lists if it is even if not one more country for the first half.

def split_list(list):
half = len(list)//2
return list[:half], list[half:]

split_list(countries)

1. ['China', 'Russia', 'USA', 'Finland', 'Sweden', 'Norway', 'Denmark']. Unpack the first three countries and the rest as scandic countries.
1st, 2nd, 3rd, *scandic = ['China', 'Russia', 'USA', 'Finland', 'Sweden', 'Norway', 'Denmark']


[<< Day 4](../04_Day_Strings/04_strings.md) | [Day 6 >>](../06_Day_Tuples/06_tuples.md)