Question

In: Computer Science

Write a program whose inputs are two integers, and whose output is the smallest of the...

Write a program whose inputs are two integers, and whose output is the smallest of the two values.

Ex: If the input is: 7 15

output is: 7

passed through command line

*in python

 

Solutions

Expert Solution

Python Program to find smallest integer value

This program accepts two integers as input from user(num1 and num2)

In this solution, two methods are given to find smallest integer value from these inputs.

Method 1 :

Using If else statements : If condition checks whether num1 is smaller than num2, if so it will print 'Smallest of these two integers is num1' .

else it will print 'Smallest of these two integers is num2'

Method 2:

Using 'min' method : using the method min(num1,num2) , program finds the smallest value and prints directly to user .

Python Program using method 1

#PYTHON PROGRAM TO FIND SMALLEST INTEGER VALUE FROM TWO INPUTS FROM USER - Method 1

#Accepts inputs from user
num1 = int (input ("Enter your first number:")) #Gets the first integer input from user and stores in num1
num2 = int (input ("Enter your second number: ")) #Gets the second integer input from user and stores in num2


#Finding output by if else
#Checks num1 smaller than num2
if (num1 < num2):
#assign num1 to small
small = num1
else:
#assign num2 to small
small = num2
  
print ("Smallest of these two integers is", small)

Python Program using method 2

#PYTHON PROGRAM TO FIND SMALLEST INTEGER VALUE FROM TWO INPUTS FROM USER - Method 2

#Accepts inputs from user
num1 = int (input ("Enter your first number:")) #Gets the first integer input from user and stores in num1
num2 = int (input ("Enter your second number: ")) #Gets the second integer input from user and stores in num2

#Finding output using min method
print("\n Smallest of these two integers is",min(num1,num2)) #Prints output to user

Output Screen using method1

Output Screen using method2

Screen shot of Python code


Related Solutions

Write a program whose inputs are three integers, and whose output is the smallest of the...
Write a program whose inputs are three integers, and whose output is the smallest of the three values
Write a program whose inputs are three integers, and whose output is the smallest of the...
Write a program whose inputs are three integers, and whose output is the smallest of the three values. Use else-if selection and comparative operators such as '<=' or '>=' to evaluate the number that is the smallest value. If one or more values are the same and the lowest value your program should be able to report the lowest value correctly. Don't forget to first scanf in the users input. Ex: If the input is: 7 15 3 the output...
Write a program Write a program whose inputs are three integers, and whose output is the...
Write a program Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 C++ please
in coral write a program whose inputs are three integers, and whose output is the largest...
in coral write a program whose inputs are three integers, and whose output is the largest of the three values. Ex: If the input is 7 15 3, the output is: 15
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values.
 in Coral Simulator  Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. If the input is 7 15 3, the output is: largest: 15 smallest: 3 Your program should define and call two functions: Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum The function LargestNumber should return the largest number of the...
Write a program whose input is two integers, and whose output is the first integer and...
Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. import java.util.Scanner; public class LabProgram {...
Write a C program whose input is two integers, and whose output is the first integer...
Write a C program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a...
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is...
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 The output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order. def swap_values(user_val1, user_val2) **in Python, please
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT