# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Homework 2
#

# In this homework you will complete a couple of simple exercises in order to show your understanding with Python. If these exercises are challenging or new to you, you may want to reconsider taking the class and/or brush up on your Python skills. For the following exercises you are not allowed to use any Python packages (i.e. Numpy, Pandas, etc.).

# ### NAME : <NAME>
# ### ID : 26636176

# ### Mandatory : Please print the output of each question below your code

# ## Lists

# 1.1 Create an empty Python list called 'a' in the cell below.

#your code here
a = []
print(a)

# 1.2 Store all values between 1-100 (inclusive) with increments of 3 (i.e. 1, 4, 7...) in 'a'.

#your code here
for i in range(1, 101, 3):
    a.append(i)
print(a)

# 1.3 Create another list called 'a2' with numbers from 2-46 (inclusive) with increments of 0.5 (i.e. 2, 2.5, 3...).

#your code here
a2 = []
i = 2
while i <= 46:
    a2.append(i)
    i += 0.5
print(a2)

# 1.4 Double every even integer element from list 'a'. Store the results back in 'a'.

#your code here
a = [i * 2 for i in a]
print(a)

# 1.5 Add all numbers in 'a' except for the 2nd and 21st elements (the 2nd element here means the element at list index 1 and similarly for the 21st element).

#your code here
ans = sum(a) - a[1] - a[20]
print(ans)

# 1.6 Calculate the mean of 'a'.

#your code here
ans = sum(a) / len(a)
print(ans)

# 1.7 Delete all elements greater than the mean value from list 'a'

#your code here
mean = sum(a) / len(a)
temp = []
for ele in a:
    if ele <= mean:
        temp.append(ele)
a = temp
print(a)

# ## Strings

# 2.1 Create an empty list called 'b'.

#your code here
b = []
print(b)

# 2.2 Store the words in the sentence below as elements into the list 'b'.  
#
# 'I am so excited about Data-X. It is important to be able to work with data.'

#your code here
sentence = 'I am so excited about Data-X. It is important to be able to work with data.'
for word in sentence.split():
    b.append(word)
print(b)

# 2.3 Return the count of the occurences of the lower-case letter 'e' in the list 'b'.

#your code here
count = 0
for word in b:
    count += word.count('e')
print(count)

# 2.4 Replace every lower- or upper-case letter 'i' in the list b with a '1'.

#your code here
for i in range(0, len(b)):
    word = b[i]
    word = word.replace('i', '1')
    word = word.replace('I', '1')
    b[i] = word
print(b)

# 2.5 Append the string "This is the end of the first HW." to the list 'b'.

#your code here
additional_sentence = "This is the end of the first HW."
for word in additional_sentence.split():
    b.append(word)
print(b)

# 2.6 Print 'b' as ONE string backwards (starting with "WH tsrif...").

#your code here
print(' '.join([ele[::-1] for ele in b[::-1]]))

# ## Dictionaries

# 3.1 Put the following in a dictionary called 'codes':
#
# Keys: 1001, 1002, 1003, 1004, 1005   
# Values: 'Alpha', 'Beta', 'Gamma', 'Delta', 'Tau'
#
# then traverse the dictionary by its keys and change every value to be all lower case.

#your code here
codes = dict()
codes[1001] = 'Alpha'
codes[1002] = 'Beta'
codes[1003] = 'Gamma'
codes[1004] = 'Delta'
codes[1005] = 'Tau'
print(codes)

# 3.2 Delete 'alpha' from the dictionary.

#your code here
if 1001 in codes:
    del codes[1001]
print(codes)

# ## Sets

# 4.1 Create a set called 'c' with the all the odd numbers less than 10.

#your code here
c = {1,3,5,7,9}
print(c)

# 4.2 Create another set called 'd' with elements 2, 5, 10, 30.

#your code here
d = {2, 5, 10, 30}
print(d)

# 4.3 Find the union between sets 'c' and 'd' and store this in a new set called 'e'.

#your code here
e = c.union(d)
print(e)

# 4.4 Find the intersection between sets 'c' and 'd'.

#your code here
intersection = c.intersection(d)
print(intersection)



StarcoderdataJupyterScriptsDedupFiltered