CS 1101 Learning Journal Unit 6 PDF

Title CS 1101 Learning Journal Unit 6
Author Khoa Le
Course Programming Fundamentals
Institution University of the People
Pages 6
File Size 191 KB
File Type PDF
Total Downloads 424
Total Views 659

Summary

Page path Home  My courses  CS 1101 - AY2021-T  4 March - 10 March  Learning Journal Unit 6Learning Journal Unit 6Part 1 Write a Python program that does the following. Create a string that is a long series of words separated by spaces. The string is your own creative choice. It can be names, ...


Description

Page path Home My courses CS 1101 - AY2021-T3 4 March - 10 March Learning Journal Unit 6

    

Learning Journal Unit 6 Part 1 Write a Python program that does the following. 

Create a string that is a long series of words separated by spaces. The string is your own creative choice. It can be names, favorite foods, animals, anything. Just make it up yourself. Do not copy the string from another source. Turn the string into a list of words using split.

 

Delete three words from the list, but delete each one using a different kind of Python operation.



Sort the list.



Add new words to the list (three or more) using three different kinds of Python operation.



Turn the list of words back into a single string using join.



Print the string.

Part 2 Provide your own examples of the following using Python lists. Create your own examples. Do not copy them from another source.      

Nested lists The “*” operator List slices The “+=” operator A list filter A list operation that is legal but does the "wrong" thing, not what the programmer expects

Provide the Python code and output for your program and all your examples. Part 3

1

Describe your experience so far with peer assessment of Programming Assignments.  

How do you feel about the aspect assessments and feedback you have received from your peers? How do you think your peers feel about the aspect assessments and feedback you provided them?

Part 1: Write a Python program that does the following. + Code: # Create a string that is a long series of words separated by spaces. weekdays = 'Monday Tuesday Wednesday Thursday Friday Saturday Sunday' # Turn the string into a list of words using split. weekdays = weekdays.split() print(weekdays) # Delete three words from the list, but delete each one using a different kind of Python operation. # Pop method weekdays_1 = weekdays.pop(6) print(weekdays) # Del method del weekdays[5] print(weekdays) # Remove method weekdays.remove('Friday') print(weekdays) # Sort the list weekdays.sort() print(weekdays) # Add new words to the list (three or more) using three different kinds of Python operation. # Append method weekdays.append('Friday') print(weekdays) # Extend method weekdays_2 = ['Saturday'] weekdays.extend(weekdays_2) print(weekdays)

2

# Insert method weekdays.insert(5, 'Sunday') print(weekdays) # + method weekdays_3 = ['Weekend'] weekdays += weekdays_3 print(weekdays) # Turn the list of words back into a single string using join. delimeter = ' ' weekdays = delimeter.join(weekdays) # Print the string. print(weekdays)

+ Output: ========================== RESTART: D:\Users\lpak\Desktop\part_1.py ========================= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] ['Monday', 'Tuesday', 'Wednesday', 'Thursday'] ['Monday', 'Thursday', 'Tuesday', 'Wednesday'] ['Monday', 'Thursday', 'Tuesday', 'Wednesday', 'Friday'] ['Monday', 'Thursday', 'Tuesday', 'Wednesday', 'Friday', 'Saturday'] ['Monday', 'Thursday', 'Tuesday', 'Wednesday', 'Friday', 'Sunday', 'Saturday'] ['Monday', 'Thursday', 'Tuesday', 'Wednesday', 'Friday', 'Sunday', 'Saturday', 'Weekend'] Monday Thursday Tuesday Wednesday Friday Sunday Saturday Weekend >>>

Part 2: Provide examples using Python lists. - Nested lists: A list has the liberty to store any object. And it is this liberty that allows it to store another list in itself. And a list that is stored in another list is said to be a nested list. For instance, we can nest a list of vowels in a list of alphabets since they are also alphabets. + Code: alphabets = ['k', 'b', 'c', 'h', 'd', 'g', 'l', 'u'] vowels = ['a', 'e', 'i', 'o', 'u'] alphabets.append(vowels) print(alphabets)

3

+ Output: ========================== RESTART: D:\Users\lpak\Desktop\part_2.py ========================= ['k', 'b', 'c', 'h', 'd', 'g', 'l', 'u', ['a', 'e', 'i', 'o', 'u']] >>>

- The “*” operator: The * operator allows you to carry out operations ranging from the multiplication of an entire list and/or its objects by specifying the object index. It is also used as an argument unpacking operator. + Code: integers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print(integers[3]) print(integers[3] * 2)

+ Output: ========================== RESTART: D:\Users\lpak\Desktop\part_2.py ========================= 4 8 >>>

- List slices: Like in strings, lists to allow slicing operations using the [:] operator. + Code: alphabets = ['k', 'b', 'c', 'h', 'd', 'g', 'l', 'u'] list_slices = alphabets[2:6] print(list_slices)

+ Output: ========================== RESTART: D:\Users\lpak\Desktop\part_2.py ========================= ['c', 'h', 'd', 'g'] >>>

- The “+=” operator: + Code:

4

integers = [1, 2, 3, 4, 5, 6, 7, 8, 9] integers += [10] print(integers)

+ Output: ========================== RESTART: D:\Users\lpak\Desktop\part_2.py ========================= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>>

- A list filter: + Code: # Check if numbers from the list are divisible by 2 integers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] result = list(filter(lambda x: (x % 2 == 0), integers)) print(result)

+ Output: ========================== RESTART: D:\Users\lpak\Desktop\part_2.py ========================= [2, 4, 6, 8, 10] >>>

- A list operation that is legal but does the "wrong" thing, not what the programmer expects : + Code: # A list operation that is legal but does the "wrong" thing integers = [1, 2, 3, 4, 5, 6, 7, 8, 9] integers = integers.append(10) # Suppose to add number 10 to the end of list print(integers) # Instead, the output is None

+ Output: ========================== RESTART: D:\Users\lpak\Desktop\test.py ========================= None >>>

5

Part 3: Describe your experience so far with peer assessment of Programming Assignments. I am satisfied with the majority of the ratings I received from my peers. I can feel that they really take efforts to read and assess my work. It helps me to develop and enrich my experience in programming and how to express myself. I think my peers are satisfied with the ratings I give to them. I know it can help them on how to write programs better and express themselves. I really hope that all of us implement the Programming Assignments properly.

Feedback Grade

10.00 / 10.00

Graded on

Sunday, 14 March 2021, 10:51 AM

Graded by

Feedback comments

Victor Brode (Instructor)

All looks correct. Great work.

6...


Similar Free PDFs