Coding Exercise for Beginners in Python |Exercise 16 | Python Tutorials for Beginners #lec47

Coding Exercise for Beginners in Python |Exercise 16 | Python Tutorials for Beginners #lec47

Python Programming: Summing Even Numbers

Introduction to the Exercise

  • The video introduces a coding exercise focused on summing all even numbers from 1 to 100, using the range function in Python.
  • It emphasizes that this task is simpler than previous exercises, which involved summing all numbers from 1 to 100.

Two Approaches to Solve the Problem

  • The first method involves initializing a total variable and using range(2, 101, 2) to iterate through even numbers directly.
  • In this approach, the loop adds each even number (2, 4, 6,... up to 100) to the total variable. The expected result is a sum of 2550.

Alternative Method Using Conditional Checks

  • The second method does not specify step size in range, iterating through all numbers from 1 to 100.
  • A conditional check (if i % 2 == 0) determines if a number is even before adding it to the total. This also results in a sum of 2550.

Conclusion and Next Steps

  • The instructor encourages viewers that they should now be familiar with using the range function effectively for such exercises and invites them to proceed with further learning.
Video description

In this Lecture we have written a Program in Python to calculate sum of even numbers from 1 to 100 using for loop and range function Best Python Tutorials for Beginners: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bZSiqiOL5ta39vSnBxpOPT ********************************************* Connect & Contact Me: My Second Channel Link: https://bit.ly/354n7C7 Facebook: https://www.facebook.com/Jennys-Lectures-CSIT-Netjrf-316814368950701/ Quora: https://www.quora.com/profile/Jayanti-Khatri-Lamba Instagram: https://www.instagram.com/jayantikhatrilamba/ Twitter: https://twitter.com/KhatriJenny ******************************************* More Playlists: Programming in C Tutorials: https://www.youtube.com/playlist?list=PLdo5W4Nhv31a8UcMN9-35ghv8qyFWD9_S C++ Tutorials for beginners: https://www.youtube.com/watch?v=KYxLEDF6kjs&list=PLdo5W4Nhv31YU5Wx1dopka58teWP9aCee Placement Series: https://www.youtube.com/playlist?list=PLdo5W4Nhv31YvlDpJhvOYbM9Ap8UypgEy Data Structures and Algorithms: https: https://www.youtube.com/playlist?list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU Design and Analysis of Algorithms(DAA): https://www.youtube.com/playlist?list=PLdo5W4Nhv31ZTn2P9vF02bkb3SC8uiUUn Dynamic Programming: https://www.youtube.com/playlist?list=PLdo5W4Nhv31aBrJE1WS4MR9LRfbmZrAQu Operating Systems tutorials: //www.youtube.com/playlist?list=PLdo5W4Nhv31a5ucW_S1K3-x6ztBRD-PNa DBMS Tutorials: https://www.youtube.com/playlist?list=PLdo5W4Nhv31b33kF46f9aFjoJPOkdlsRc #coding #pythonforbeginners #python #jennyslectures #pythonprogramming #codingquestions