# Noemi Cabrera
# 27 October 2021
# In this lesson, I learned to add items to the end of a list using the .append() method.
# The item you want to add, a string, integer or list, is placed in the parentheses.
# I also appended items to a list with input(). The input is stored in a variable and
# then the variable is placed in the parentheses. Also, I learned to use the while loop
# with append to repeat code and add items into a defined list.
# I didn't have any difficulties in this lesson.
# [ In this code, the .append()method is applied to sample_list. This method adds an item placed in the
# parentheses to the end of a list. The sample_list is displayed as it is and then it's displayed with
# the added item at the end on a second line. ] review and run example
# the list before append
sample_list = [1, 1, 2]
print("sample_list before: ", sample_list)
sample_list.append(3)
# the list after append
print("sample_list after: ", sample_list)
# [ In this code, the sample_list vaiable created in the code above is used. The
# .append() method is used to add an item, in this case an integer, to the end of the
# sample list. In total, 3 integers are added. ] review and run example
# append number to sample_list
print("sample_list start: ", sample_list)
sample_list.append(3)
print("sample_list added: ", sample_list)
# append again
sample_list.append(8)
print("sample_list added: ", sample_list)
# append again
sample_list.append(5)
print("sample_list added: ", sample_list)
# [ ] run this cell several times in a row
# [ ] run cell above, then run this cell again
# [ The .append() method is used to add an item, in this case an integer and string, to
# the end of the mixed_types list. In total, 1 integer and 1 string are added. The list
# is a mix of integers and strings. ] review and run example
mixed_types = [1, "cat"]
# append number
mixed_types.append(3)
print("mixed_types list: ", mixed_types)
# append string
mixed_types.append("turtle")
print("mixed_types list: ", mixed_types)
# Currency Values
# [ In this code, the cur_values variable contains a list with values of coins and paper
# bills. ] create a list of 3 or more currency denomination values, cur_values
# cur_values, contains values of coins and paper bills (.01, .05, etc.)
cur_values = [.10, 0.25, 1, 5, 10]
# [ The original list is printed first. ] print the list
print(cur_values)
# [ The integer 20 is added to the end of the list and the list is printed again with
# the added item. ] append an item to the list and print the list
cur_values.append(20)
print(cur_values)
# Currency Names
# [ In this code, the cur_names variable contains a list with names of coins and paper
# bills. ] create a list of 3 or more currency denomination NAMES, cur_names
# cur_names contains the NAMES of coins and paper bills (penny, etc.)
cur_names = ["penny", "nickel", "dime", "one dollar", "five dollars"]
# [ The original list is printed first. ] print the list
print(cur_names)
# [ The string "fifty dollars" is added to the end of the list and the list is printed
# again with the added item. ] append an item to the list and print the list
cur_names.append("fifty dollars")
print(cur_names)
# [In this code, the cur_names variable defined above is used. The user is asked to enter
# a name of a coin or paper bill used in the U.S. The variable add_cur_name,
# which contains the input, is appended to the cur_names list.]
# append additional values to the Currency Names list using input()
add_cur_name = input("Enter a name of a coin or paper bill used in the U.S : ").lower()
cur_names.append(add_cur_name)
# [The final list is printed. ] print the appended list
print(cur_names)
# [ In this code, the .append() method is used along with a while loop. The user is asked
# to enter the day of the month they were born. As long as their answer is not "q", the
# user will be asked over an over to enter an answer. If answer is "q" the list will be
# printed] complete the Birthday Survey task above
bday_survey = []
while True:
bday = input("Please enter the day of the month you were born (1-31) or 'q' to finish:" ).lower()
if bday != "q":
bday_survey.append(bday)
else:
print("List ended")
break
print("Final list:", bday_survey)
# [ The error in this code was that the index 3 used to do the slice was not found in
# the list three_numbers because the list only has indexes 0, 1, and 2. To fix this, I
# changed the index count on the slice to 2, so that the last item in the list is
# printed.] Fix the Error
three_numbers = [1, 1, 2]
print("an item in the list is: ", three_numbers[2])