🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. Introduction
Calculating the average of a list of numbers is a common operation in various fields, including statistics, education, and data analysis. Python provides a straightforward way to accomplish this task, which is often essential for understanding trends and making decisions.
Definition
The average, or mean, of a list is calculated by summing all the elements in the list and then dividing that total by the number of elements.
2. Program Steps
1. Define a list of numerical values.
2. Compute the sum of all elements in the list.
3. Divide the total sum by the count of the elements in the list to find the average.
4. Print the computed average.
3. Code Program
# Step 1: Define a list of numbers
numbers = [2, 4, 6, 8, 10, 12]
# Step 2: Calculate the sum of the list
total_sum = sum(numbers)
# Step 3: Find the count of numbers in the list
number_count = len(numbers)
# Calculate the average
average = total_sum / number_count
# Step 4: Print the average
print(f"The average of the list is: {average}")
Output:
The average of the list is: 7.0
Explanation:
1. numbers is a list containing six integers.
2. total_sum is calculated using the built-in sum() function, which adds up all elements in numbers.
3. number_count is obtained by the len() function, which counts the number of elements in numbers.
4. The average is computed as total_sum divided by number_count.
5. The final print statement outputs the computed average using an f-string to insert the calculated value into the message, showing that the average is 7.0.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment