Computer Science, asked by vpyvpyadav12, 5 months ago

write a Python program.To find and print the greatest number out of two inputs.​

Answers

Answered by josnaelsajoseph
3

Answer:

Greatest of Two Numbers in Python | Python Program to Print Greatest of Two Numbers

Explanation:

In this article, we will discuss how to print the greatest of two numbers using different methods.

greatest of two numbers

INPUT FORMAT:

Input Consists of 2 integers

OUTPUT FORMAT:

A single integer which is the greatest of the two given input integers

SAMPLE INPUT:

Method 1: Using Built-In Function

Algorithm to print the greatest of two numbers using the built-in function

Step 1: Get 2 inputs from the user

Step 2: Find the greatest of two numbers using the built-in function 'max'

Step 3: Print the output

Step 5: End

Python program to print the greatest of two numbers using the built-in function

# Python program to find the greatest of two numbers using the built-in function

num1 = int(input("Enter the first number: "))

num2 = int(input("Enter the second number: "))

print(max(num1, num2), "is greater")

Input:

Enter the first number: 23

Enter the second number: 45

Output:

45 is greater

Method 2: Using if-else statements

Algorithm to print the greatest of two numbers using if-else statements

Step1: Get the 2 inputs from the user

Step 2: Check whether the first value is greater than the second value

Step 3: If yes, print the first value

Step 4: Else, print the second value

Step 5: End

Python program to print the greatest of two numbers using if-else statements

# Python Program to find Largest of two Numbers using if-else statements

a = int(input("Enter the first number: "))

b = int(input("Enter the second number: "))

if(a >= b):

print(a, "is greater")

else:

print(b, "is greater")

Input:

Enter the first number: 50

Enter the second number: 45

Output:

50 is greater

Method 3: Using Arithmetic operator

Python program to print the greatest of two numbers using an arithmetic operator

# Python Program to find the largest of two numbers using an arithmetic operator

a = int(input("Enter the first number: "))

b = int(input("Enter the second number: "))

if(a - b > 0):

print(a, "is greater")

else:

print(b, "is greater")

Input:

Enter the first number: 90

Enter the second number: 100

Output:

100 is greater

45

86

SAMPLE OUTPUT:

86

Similar questions