Question

In: Computer Science

Summary In this lab, you complete a prewritten Python program that computes the largest and smallest...

Summary

In this lab, you complete a prewritten Python program that computes the largest and smallest of three integer values. The three values are -50, 53, 78.

Instructions

  1. Two variables named largestand smallest are assigned for you. Use these variables to store the largest and smallest of the three integer values. You must decide what other variables you will need and initialize them if appropriate.
  2. Write the rest of the program using assignment statements, if statements, or elifstatements as appropriate. There are comments in the code that tell you where you should write your statements. The output statements are written for you.
  3. Execute the program. Your output should be:
    The largest value is 78
    The smallest value is -50

# LargeSmall.py - This program calculates the largest and smallest of three integer values.
# Declare and initialize variables here
firstNumber = -50;
secondNumber = 53;
thirdNumber = 78;

# Write assignment, if, or if else statements here as appropriate

# Output largest and smallest number.
print("The largest value is " + str(largest))
print("The smallest value is " + str(smallest))

Solutions

Expert Solution

Thanks for the question, here is the simple short python code to find the largest and smallest number among the 3 numbers.

====================================================================

firstNumber = -50
secondNumber = 53
thirdNumber = 78

if (firstNumber >= secondNumber and firstNumber >= thirdNumber):
    largest = firstNumber
elif (secondNumber >= firstNumber and secondNumber >= thirdNumber):
    largest = secondNumber
else:
    largest = thirdNumber

if (firstNumber <= secondNumber and firstNumber <= thirdNumber):
    smallest = firstNumber
elif (secondNumber <= firstNumber and secondNumber <= thirdNumber):
    smallest = secondNumber
else:
    smallest = thirdNumber

print('The largest value is ' + str(largest))
print('The smallest value is ' + str(smallest))


Related Solutions

Understanding if-elseStatements Summary In this lab, you will complete a prewritten Java program that computes the...
Understanding if-elseStatements Summary In this lab, you will complete a prewritten Java program that computes the largest and smallest of three integer values. The three values are –50, 53, and 78. Instructions Two variables named largest and smallest are declared for you. Use these variables to store the largest and smallest of the three integer values. You must decide what other variables you will need and initialize them if appropriate. Write the rest of the program using assignment statements, if...
Python - You are given a sorted (from smallest to largest) array A of n distinct...
Python - You are given a sorted (from smallest to largest) array A of n distinct integers which can be positive, negative or zero. Design the fastest algorithm you can for deciding if there is an index i such that A[i] = i.
Summary In this lab, you complete a prewritten Java program that calculates an employee’s productivity bonus...
Summary In this lab, you complete a prewritten Java program that calculates an employee’s productivity bonus and prints the employee’s name and bonus. Bonuses are calculated based on an employee’s productivity score as shown below. A productivity score is calculated by first dividing an employee’s transactions dollar value by the number of transactions and then dividing the result by the number of shifts worked. Productivity Score Bonus <=30 $50 31–69 $75 70–199 $100 >= 200 $200 Instructions Ensure the file...
"Using Python, code to find the smallest and largest planet mass (if known), and plot these...
"Using Python, code to find the smallest and largest planet mass (if known), and plot these as two curves against the year of discovery" Basically looking to use data from an excel sheet where 'disc_year' and 'pl_mass' are columns of data; and code Python to find the maximum value of mass and the minimum value of mass for each year, then plot this as two curves. There are multiple planets for any given year hence multiple values for mass. Below...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Summary In this lab, you will make additions to a C++ program that is provided. The...
Summary In this lab, you will make additions to a C++ program that is provided. The program is a guessing game. A random number between 1 and 10 is generated in the program. The user enters a number between 1 and 10, trying to guess the correct number. If the user guesses correctly, the program congratulates the user, and then the loop that controls guessing numbers exits; otherwise, the program asks the user if he or she wants to guess...
• Write a C++ program to find the largest umber, smallest number and sum of all...
• Write a C++ program to find the largest umber, smallest number and sum of all the element of a given array of 20 integers • Note − Declare array to 20 numbers − Input values for 20 array elements − Find largest number − Find smallest number − Find sum of all numbers • Display the results
Write a Python program to find the smallest positive integer that is a perfect square and...
Write a Python program to find the smallest positive integer that is a perfect square and it contains exactly three different digits.
Writing a Modular Program in Python In this lab, you add the input and output statements...
Writing a Modular Program in Python In this lab, you add the input and output statements to a partially completed Python program. When completed, the user should be able to enter a year, a month, and a day. The program then determines if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31. Instructions Notice that variables have been declared...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT