Question

Two variables named largest and smallest are assigned for you. Use these variables to store the...

  1. Two variables named largest and 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 elif statements 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 integervalues. # Declare and initialize variables herefirstNumber = -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))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Here is the python code as per your requirement

Raw code:

#declaring given variables in question

firstNumber = -50

secondNumber = 53

thirdNumber = 78

#checking if the first number is greater than the second and third

if firstNumber>secondNumber and firstNumber>thirdNumber:

#if yes store the first in largest

largest=firstNumber

#checking if the second number is greater than the first and third

elif secondNumber>firstNumber and secondNumber>thirdNumber:

#if yes store the second in largest

largest=secondNumber

#if both aren't largest nmbers then the remaining will be largest so assign third to largest

else:

largest=thirdNumber

#checking if the first number is smaller than the second and third

if firstNumber<secondNumber and firstNumber<thirdNumber:

#if yes store the first in smallest

smallest=firstNumber

#checking if the second number is lesser than the first and third

elif secondNumber<firstNumber and secondNumber<thirdNumber:

#if yes store the second in smallest

smallest=secondNumber

#if both aren't smaller nmbers then the remaining will be smaller so assign third to smallerst

else:

smallest=thirdNumber

#printing values

print("The largest value is " + str(largest))

print("The smallest value is " + str(smallest))

Editor:

3 6 1 9 10 14 main.py 1 #declaring given variables in question 2 firstNumber = -50 3 secondNumber = 53 4 thirdNumber = 78 5 #

output:

The Largest value is 78 The smallest value is -50 1

Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.

"Please refer to the screenshot of the code to understand the indentation of the code".

Thank you! Do upvote.

Add a comment
Know the answer?
Add Answer to:
Two variables named largest and smallest are assigned for you. Use these variables to store the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Swapping Values in python Summary In this lab, you complete a Python program that swaps values...

    Swapping Values in python Summary In this lab, you complete a Python program that swaps values stored in three variables and determines maximum and minimum values. The Python file provided for this lab contains the necessary input and output statements. You want to end up with the smallest value stored in the variable named first and the largest value stored in the variable named third. You need to write the statements that compare the values and swap them if appropriate....

  • I need help with this. Can someone please show me the solution. Declaring and Initializing Java...

    I need help with this. Can someone please show me the solution. Declaring and Initializing Java Variables Summary In this lab, you declare and initialize variables in a Java program. The program file named NewAge.java, calculates your age in the year 2050. Instructions Declare an integer variable named newAge. Declare and initialize an integer variable named currentAge. Initialize this variable with your current age. Declare and initialize an integer variable named currentYear. Initialize this variable with the value of the...

  • Multiple Conditional Statements Summary In this lab, you complete a Python program that calculates an employee's...

    Multiple Conditional Statements Summary In this lab, you complete a Python program that calculates an employee's annual bonus. Input is an employee's first name, last name, salary, and numeric performance rating. If the rating is 1, 2, or 3, the bonus rate used is .25, .15, or .1 respectively. If the rating is 4 or higher, the rate is 0. The employee bonus is calculated by multiplying the bonus rate by the annual salary. Variables have been declared for you,...

  • Please help, In this lab, you complete a prewritten C++ program for a carpenter who creates...

    Please help, In this lab, you complete a prewritten C++ program for a carpenter who creates personalized house signs. The program is supposed to compute the price of any sign a customer orders, based on the following facts: The charge for all signs is a minimum of $35.00. The first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character. If the sign is made of oak, add $20.00. No charge...

  • Write a JAVA program to read a list of nonnegative integers and to display the largest...

    Write a JAVA program to read a list of nonnegative integers and to display the largest integer, the smallest integer and the average of all the integers. The user indicates the end of the input by entering a negative sentinel value that is not used in finding the largest, smallest and average values. The average should be a value of type double so that it is computed a fractional part. * Java program free from syntax, logic and run time...

  • Exercise3 Suppose you have several points with coordinates (xk, v) located in the 2-D plane. The points are sorted from smallest to largest x coordinate. You want to find the slope of the line betwee...

    Exercise3 Suppose you have several points with coordinates (xk, v) located in the 2-D plane. The points are sorted from smallest to largest x coordinate. You want to find the slope of the line between each successive pair of points, i.e., between (xbw) and (xkl.yk. These are the points: (-5, 9), (-1, 5), (2,7), (8, 12), (13, 5), (15, -4), (20, 0), (45, 3), (66, 10), (70, 8) Write a program that meets these requirements: Create a 1-D array named...

  • (C++) Topic: Please write a function Order (int *largest, int *medium, int*smallest). The function of this...

    (C++) Topic: Please write a function Order (int *largest, int *medium, int*smallest). The function of this function is to rearrange the value of the whole index pointed to by the three indicators, that is, how to set the indicator that is passed in. If the function ends, it must be largest to point to the largest value, smallest to the smallest value, medium to point to The value in the middle. For example, consider the following main(). The order of...

  • Write a C program that will do the following: 1.Declare four integers variables.   intVar1, intVar2, intVar3,and...

    Write a C program that will do the following: 1.Declare four integers variables.   intVar1, intVar2, intVar3,and intVar4. 2. Initialize intVar1 to the value 4; initialize intVar2to the value 5. 3. Declare four more integer variables. exp1, exp2,exp3, and exp4. 4. Declare a character variable charVar. 5. Assign the value of each expression below to variables exp1and exp2 respectively: exp1= intVar1 + ((5 * intVar2) / (3 * intVar1)); exp2 = intVar1 + (5 * (intVar2 / 3)) * intVar1; 6....

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Write an assembly program which prints the largest values among three variables. You can initialize three...

    Write an assembly program which prints the largest values among three variables. You can initialize three integers in data section (let's say 10, 45, 15).

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT