Question

sentinel_min_max Python 3.x request: Thanks for any assistance! Write a sentinel loop that repeatedly prompts the...

sentinel_min_max Python 3.x request: Thanks for any assistance!

Write a sentinel loop that repeatedly prompts the user to enter a number and, once the number -1 is typed, displays the maximum and minimum numbers that the user entered. Here is a sample dialogue:

Type a number (or -1 to stop): 5
Type a number (or -1 to stop): 2
Type a number (or -1 to stop): 17
Type a number (or -1 to stop): 8
Type a number (or -1 to stop): -1
Maximum was 17
Minimum was 2

This exercise asks for bare code. Submit a fragment of Python code as described. Do not write any class or function/method heading around your code; just write the lines of code that will produce the result described.

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

Solution is provided below. Please comment if any doubt.

Python screen shot:

Python Code:

# Declare variable num
num=0
# Initialize list
lst=[]
#while num not equal to -1
while num!=-1:
# Enter the number
num=int(input("Type a number (or -1 to stop): "))
# if number is not equal to -1
if num!=-1:
# Append the number to lisr
lst.append(num)
# Find maximum of the list
print("Maximum was %d"%max(lst))
# Find minimum of list
print("Minimum was %d"%min(lst))

Output:

Add a comment
Know the answer?
Add Answer to:
sentinel_min_max Python 3.x request: Thanks for any assistance! Write a sentinel loop that repeatedly prompts 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