Iterating using For loop | Syntax

Published: 04 March 2019
on channel: EdYoda
260
4

For more courses visit : https://www.edyoda.com/

In this video we will discuss how to write the for loop to iterate over a collection of element and perform certain operation on every element. We will also discuss the built in range() function to generate series of numbers.

Practice Problem:

1) Write a Python program that sums all of the first integers, the second integers, and the third integers, outputting the resulting sums all.

if the input is

[2, 5,7]

[3, 6, 10]

[1, 2, -3]

[2, 4, 1]

Then the output should be

[8, 17, 15]

2) v is a list containing numbers. Write Python code to find and print the highest two values in v. If the list contains only one number, print only that number. If the list is empty, print nothing. For example,

v = [ 7, 3, 1, 5, 10, 6 ]

Output l = [7,10]


Watch video Iterating using For loop | Syntax online without registration, duration hours minute second in high quality. This video was added by user EdYoda 04 March 2019, don't forget to share it with your friends and acquaintances, it has been viewed on our site 260 once and liked it 4 people.