Friday, May 17, 2019

Abhijeet Pal: Python Program to Find the Smallest Among Three Numbers

Problem Definition

Create a Python program to find the smallest among the three given numbers, taking runtime inputs from the user.

Solution

  1. Take inputs from the user and store them in variables
  2. Compare the numbers
  3. Print the final result
  4. End

To understand the program you need to have an understanding of following Python concept.

Program

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

if (num1 < num2) and (num1 < num3):
    smallest = num1
elif (num2 < num1) and (num2 < num3):
    smallest = num2
else:
    smallest = num3

print("The smallest number is", smallest)

Runtime Test Cases

Enter first number: 90
Enter second number: 34
Enter third number: 69
The smallest number is 34.0

Explanation

First, the program is taking input from the keyboard using the built-in input() function. Although we do need to change the datatype of the inputs to either integer or float, we are converting the input to float for more accuracy.

Next, there are 3 conditional statements which will store the smallest number into the variable smallest which later gets printed out.

The post Python Program to Find the Smallest Among Three Numbers appeared first on Django Central.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...