🎓 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
Determining the largest number out of a set is a basic computational task and an essential part of decision-making processes in programming. Python provides several methods to achieve this, from using conditional statements to built-in functions.
2. Problem Statement
Create a Python program that finds the largest number among three given numbers, without using built-in functions like max.
3. Solution Steps
1. Take three numbers as input.
2. Compare the first number with the second and third numbers.
3. Determine the largest number using conditional statements.
4. Print the largest number found.
4. Code Program
# Define the function to find the largest number among three
def find_largest(num1, num2, num3):
# Compare each number
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
return largest
# Given numbers
number1 = 15
number2 = 27
number3 = 12
# Call the function to find the largest number
largest_number = find_largest(number1, number2, number3)
# Print the largest number
print(f"The largest number among {number1}, {number2}, {number3} is: {largest_number}")
Output:
The largest number among 15, 27, 12 is: 27
Explanation:
1. find_largest is a function that takes three arguments, num1, num2, and num3.
2. It uses nested conditional if-elif-else statements to compare the numbers.
3. The if condition checks if num1 is greater than or equal to both num2 and num3. If true, num1 is the largest.
4. The elif condition similarly checks if num2 is the largest.
5. The else condition concludes that if neither num1 nor num2 is the largest, then num3 must be.
6. The function returns the largest number, which is stored in largest_number.
7. The print statement outputs the result using an f-string to format the message, indicating that among the given numbers, 27 is the largest.
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