Computer Science G10 T3- 2018\2017 T shaikhah AlZeyoudi Dibba Al Fujairah
Week2 Unit5 – Lesson2 P. #19-26 Term3 -- Python Unit 5 - Data structures Week2 Unit5 – Lesson2 P. #19-26 15 Apr 2018
Explain the use of loops with lists. loop, list Explain the use of loops with lists. Demonstrate and let the students experiment with using for and while loops in conjunction with lists. Show and explain how to create lists dynamically.
Review last lesson Lists
Explain the use of loops with lists
for i in range (0,3,1): print(i)
Reading and writing data in lists
Counter x Square 1 2 4 3 9 16 5 25 6 36 7 49 8 64
set values Using a loop to
user inputs Using a loop to
Using a loop to printing
Creating Empty List
You may not have the data or know the size of your list before your program starts. You can create an empty list first, and then add elements and values later NAME = []
append( ) function
NAME.append(“stud1”) NAME.append(“stud2”)
append( ) function to add value List
student_Grades=[] finish="no" while finish=="no": grade=input("Enter the Grade :") grade=int(grade) student_Grades.append(grade) finish=input("Are you Finished ? ") print(student_Grades)
Activity
Activity 2: Using loops to set and read values in a list
Open: 10-Term3 2-Select you class folder 10A-….. 10G-…..
1 2 4 3
Week2-NAME Now Open new python name as: Applied the Task sheet If you finish: Save your answer Run the output Ask the teacher to correct Week2-NAME