Skip to content

Commit c6b45b5

Browse files
committed
practiced functions with arguments and looping lists
1 parent 6d7d8f2 commit c6b45b5

File tree

19 files changed

+77
-15
lines changed

19 files changed

+77
-15
lines changed

exercises/01.3-Print-the-last-one/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ def generate_random_list():
1313
my_stupid_list = generate_random_list()
1414

1515
# Write your code below this comment, good luck!
16-
16+
the_last_one = my_stupid_list[-1]
17+
print(the_last_one)

exercises/01.4-loop-seventeen/app.py

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Your code here, have fun:
2+
for i in range(1,18):
3+
print(i)
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Remember to import random function here
2-
2+
import random
33
my_list = [4, 5, 734, 43, 45]
44

55
# The magic goes below
6+
for i in range(10):
7+
my_list.append(random.randint(1,100))

exercises/02-Loop-list/app.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
my_list = [232,32,1,4,55,4,3,32,3,24,5,5,5,34,2,35,5365743,52,34,3,55]
22

33
# Your code here
4-
print(my_list[0])
4+
# print(my_list[0])
5+
for i in my_list:
6+
print(i)

exercises/02.1-Loop-from-the-top/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# Modify the loop below to print from end to start
44

55
for i in range(0, len(my_sample_list)):
6-
print(my_sample_list[i])
6+
print(my_sample_list[len(my_sample_list)-1-i])

exercises/02.2-Loop-adding-two/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
# Your code below, don't change anything above
44

5-
for i in range(0, len(my_sample_list), 1):
5+
for i in range(0, len(my_sample_list), 2):
66
print(my_sample_list[i])
77

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
my_list = [3423,5,4,47889,654,8,867543,23,48,56432,55,23,25,12]
22

33
# Your code here
4-
inicial_value = 0
5-
stop_value = 0
6-
increase_value = 0
4+
inicial_value = int(len(my_list)/2)
5+
stop_value = len(my_list)
6+
increase_value = 1
77

88
for i in range(inicial_value, stop_value, increase_value):
99
print(my_list[i])

exercises/02.5-Finding_wally/app.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
people = ['Lebron','Aaliyah','Diamond','Dominique','Aliyah','Jazmin','Darnell','Hatfield','Hawkins','Hayden','Hayes','Haynes','Hays','Head','Heath','Hebert','Henderson','Hendricks','Hendrix','Henry','Hensley','Henson','Herman','Hernandez','Herrera','Herring','Hess','Hester','Hewitt','Hickman','Hicks','Higgins','Hill','Hines','Hinton','Hobbs','Hodge','Hodges','Hoffman','Hogan','Holcomb','Holden','Holder','Holland','Holloway','Holman','Holmes','Holt','Hood','Hooper','Hoover','Hopkins','Hopper','Horn','Horne','Horton','House','Houston','Howard','Howe','Howell','Hubbard','Huber','Hudson','Huff','Wally','Hughes','Hull','Humphrey','Hunt','Hunter','Hurley','Hurst','Hutchinson','Hyde','Ingram','Irwin','Jackson','Jacobs','Jacobson','James','Jarvis','Jefferson','Jenkins','Jennings','Jensen','Jimenez','Johns','Johnson','Johnston','Jones','Jordan','Joseph','Joyce','Joyner','Juarez','Justice','Kane','Kaufman','Keith','Keller','Kelley','Kelly','Kemp','Kennedy','Kent','Kerr','Key','Kidd','Kim','King','Kinney','Kirby','Kirk','Kirkland','Klein','Kline','Knapp','Knight','Knowles','Knox','Koch','Kramer','Lamb','Lambert','Lancaster','Landry','Lane','Lang','Langley','Lara','Larsen','Larson','Lawrence','Lawson','Le','Leach','Leblanc','Lee','Leon','Leonard','Lester','Levine','Levy','Lewis','Lindsay','Lindsey','Little','Livingston','Lloyd','Logan','Long','Lopez','Lott','Love','Lowe','Lowery','Lucas','Luna','Lynch','Lynn','Lyons','Macdonald','Macias','Mack','Madden','Maddox','Maldonado','Malone','Mann','Manning','Marks','Marquez','Marsh','Marshall','Martin','Martinez','Mason','Massey','Mathews','Mathis','Matthews','Maxwell','May','Mayer','Maynard','Mayo','Mays','Mcbride','Mccall','Mccarthy','Mccarty','Mcclain','Mcclure','Mcconnell','Mccormick','Mccoy','Mccray','Wally','Mcdaniel','Mcdonald','Mcdowell','Mcfadden','Mcfarland','Mcgee','Mcgowan','Mcguire','Mcintosh','Mcintyre','Mckay','Mckee','Mckenzie','Mckinney','Mcknight','Mclaughlin','Mclean','Mcleod','Mcmahon','Mcmillan','Mcneil','Mcpherson','Meadows','Medina','Mejia','Melendez','Melton','Mendez','Mendoza','Mercado','Mercer','Merrill','Merritt','Meyer','Meyers','Michael','Middleton','Miles','Miller','Mills','Miranda','Mitchell','Molina','Monroe','Lucas','Jake','Scott','Amy','Molly','Hannah','Lucas']
22

33
# Your code here
4+
5+
for i in range(len(people)):
6+
if people[i]=="Wally":
7+
print(i)

exercises/03-flip_list/app.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
sample_list = [45, 67, 87, 23, 5, 32, 60]
22

33
# Your code below
4+
new_list = []
5+
for i in range(len(sample_list)):
6+
new_list.append(sample_list[-1-i])
7+
8+
print (new_list)

exercises/04-mixed_list/app.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
mix = [42, True, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]
22

33
# Your code below
4+
for i in mix:
5+
print(type(i))

exercises/04.1-count_on/app.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
my_list = [42, True, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]
22

33
# Your code here
4+
new_list=[]
5+
for i in range(len(my_list)):
6+
if type(my_list[i]) == list or type(my_list[i]) == dict:
7+
new_list.append(my_list[i])
8+
print(new_list)

exercises/05-Sum_all_items/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
def sum_all_values(list):
44
total = 0
55
# The magic happens here
6-
6+
for num in my_sample_list:
7+
total+=num
78

89
return total
910

exercises/05.1-sum_odd_items/app.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
my_list = [4,5,734,43,45,100,4,56,23,67,23,58,45]
22

33
# Your code here
4+
def sum_odds(list):
5+
odd_numbers = 0
6+
for num in list:
7+
if num%2 != 0:
8+
odd_numbers += num
9+
return odd_numbers
10+
11+
print(sum_odds(my_list))
12+

exercises/06-Print_by_condition/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
for i in my_list:
55
# The magic happens here
6-
6+
if i % 14 == 0:
7+
print(i)

exercises/06.1-Everything_is_awesome/app.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ def my_function(numbers):
44
new_list = []
55
for i in numbers:
66
# The magic happens here
7-
7+
if i == 0:
8+
new_list.append("Yahoo")
9+
else:
10+
new_list.append(i)
811

912
return new_list
1013

exercises/07-Do_while/app.py

+9
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
# Your code here
2+
number = 20
3+
while number >=0:
4+
if number == 0:
5+
print("LIFTOFF")
6+
elif number % 5 == 0:
7+
print(str(number)+"!")
8+
else:
9+
print(number)
10+
number-=1

exercises/08-Delete_element/app.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
def delete_person(person_name):
44
# Your code here
5-
6-
5+
new_list = []
6+
for name in people:
7+
if name != person_name:
8+
new_list.append(name)
9+
return new_list
710

811
# Don't delete anything below
912
print(delete_person("daniella"))

exercises/08.1-Merge_list/app.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
def merge_list(list1, list2):
66
# Your code here
7-
8-
7+
new_list = []
8+
for i in list1:
9+
new_list.append(i)
10+
for i in list2:
11+
new_list.append(i)
12+
return new_list
913
print(merge_list(chunk_one, chunk_two))

exercises/08.2-Divide_and_conquer/app.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
list_of_numbers = [4, 80, 85, 59, 37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68]
22

33
# Your code here
4+
def sort_odd_even(list):
5+
sorted_list = []
6+
even = []
7+
for num in list:
8+
if num % 2 != 0:
9+
sorted_list.append(num)
10+
else:
11+
even.append(num)
12+
return sorted_list+even
413

514

615
print(sort_odd_even(list_of_numbers))

0 commit comments

Comments
 (0)