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
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
ADVERTISEMENT