Instantly share code, notes, and snippets.

@jennyonjourney

jennyonjourney / 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try,

  • Download ZIP
  • Star ( 11 ) 11 You must be signed in to star a gist
  • Fork ( 5 ) 5 You must be signed in to fork a gist
  • Embed Embed this gist in your website.
  • Share Copy sharable link for this gist.
  • Clone via HTTPS Clone using the web URL.
  • Learn more about clone URLs
  • Save jennyonjourney/c032a1f4e25d4d03e4601b3536f77f92 to your computer and use it in GitHub Desktop.
largest = None
smallest = None
while True:
inp = raw_input("Enter a number: ")
if inp == "done" : break
try:
num = float(inp)
except:
print ("Invalid input")
continue
if smallest is None:
smallest = num
if num > largest :
largest = num
elif num < smallest :
smallest = num
def done(largest,smallest):
print ("Maximum is", int(largest))
print ("Minimum is", int(smallest))
done(largest,smallest)

@SmaranikaBiswas

SmaranikaBiswas commented Sep 25, 2021

largest = None smallest = None num = 0 while True: num = input("Enter a number: ") if num == "done" : break try: numb = int(num) except: print ("Invalid input") continue if smallest is None: smallest = numb elif numb < smallest : smallest = numb if largest is None: largest = numb elif numb > largest: largest = numb print ("Maximum is", largest) print ("Minimum is", smallest)

This is a correct code. It's absolutely run and match the output.

Sorry, something went wrong.

@KhaledE21

KhaledE21 commented Nov 14, 2021

image

mdshamimchowdhury commented Jan 19, 2022

Now you Must Try This one

num = 0 largest = -1 smallest = None while True: num = input("Enter a number: ") if num == "done" : break try : numb = int(num) except : print('Invalid input') if smallest is None : smallest = numb elif numb < smallest : smallest = numb elif numb > largest : largest = numb print("Maximum is", largest) print("Minimum is", smallest)

Now you should try to enter output: 7 then 2 then bob then 10 then 4 then done

@initiatorvaibhav

initiatorvaibhav commented Feb 21, 2022

# newer update

largest = None smallest = None while True: inp = input("Enter a number: ") if inp == "done": break try: num = float(inp) except: print("Invalid input") continue if smallest is None: smallest = num largest = num if num < smallest: smallest = num elif num > largest: largest = num print("Maximum is", int(largest)) print("Minimum is", int(smallest))

@rovesoul

rovesoul commented Feb 21, 2022 via email

@Abi-London

Abi-London commented Mar 21, 2022

largest = None smallest = None while True: num = input("Enter a number: ") if num == "done": break try: numb=int(num) except: print('Invalid input') continue if largest is None: largest=numb elif largest<numb: largest=numb if smallest is None: smallest=numb elif numb<smallest: smallest=numb print("Maximum", largest) print("Minimum", smallest)

rovesoul commented Mar 21, 2022 via email

@chenchen218

chenchen218 commented May 10, 2022

my code for this practice:

large = None small = None

while True: num = input('please enter a vallue<<') try: if num == 'done': print('program finished') break number = int(num) except: print('please enter a numeric value') if small is None or small > number: small = number if large is None or large < number: large = number

print('MAX NUM: ',large, 'MIN NUM:',small)

rovesoul commented May 10, 2022 via email

@WitherspoonD

WitherspoonD commented Oct 16, 2022

The code checker is case sensitive.

rovesoul commented Oct 16, 2022 via email

@techfresher

techfresher commented Nov 23, 2022

Capture online assignment

please help out

rovesoul commented Nov 23, 2022 via email

Rovesoul commented jan 9, 2023 via email.

@mohamednazeih

mohamednazeih commented Jan 16, 2023

largest = None smallest = None while True: num = input("Enter a number: ")

print("Maximum is", largest) print("Minimum is", smallest)

@amw514

amw514 commented Apr 3, 2023

Rovesoul commented apr 3, 2023 via email.

@iqtidarali

iqtidarali commented Apr 17, 2023

image

work for me hope for you guys as well

rovesoul commented Apr 17, 2023 via email

@anitasoaares

anitasoaares commented May 29, 2023 • edited Loading

image

rovesoul commented May 29, 2023 via email

@Irajam

Irajam commented Aug 27, 2023

can pls someone help me, i have been trying a lot of different things and this mismatch is always appearing. I dont know what i am doing wrong. I have tried without the quit() but is the same thing.

did you find any solution for this? i have same issue, i tried several codes but not working

rovesoul commented Aug 27, 2023 via email

 alt=

mike-official commented Sep 14, 2023

Rovesoul commented sep 14, 2023 via email.

@tadeletekeba13

tadeletekeba13 commented Oct 14, 2023

"Hello, everyone. Could you kindly assist me with this exercise?

I am encountering difficulties, and nothing seems to be effective.

largest = None smallest = None

while True : num = input ('Enter a number :') if num=='done': break #elif num =='Done': #break try : fnum = float (num ) except: print ('Invaild input') continue if largest in None: largest = fnum elif fnum > largest: largest = fnum #print (fnum) if smallest is None : smallest =fnum #print (fnum) Print ('Maximum is', int(largest)) Print ('Minimum is' , int(smallest)) IS NOT WORKIG

Exercise 5 2 is no

rovesoul commented Oct 14, 2023 via email

Rovesoul commented oct 30, 2023 via email.

@HyugasV

HyugasV commented Oct 30, 2023

Guys my code is like that and it's working is it true ?

numlist = [] while True: num = input("Enter a number: ") if num == "done": break try: num = int(num) (numlist.append(num)) largest = max(numlist) smallest = min(numlist) except: print("Invalid input")

Python for Everybody

  • Coursera: Python for Everybody Specialization
  • edX: Python for Everybody
  • FutureLearn: Programming for Everybody (Getting Started with Python)
  • FreeCodeCamp
  • Free certificates for University of Michigan students and staff

If you log in to this site you have joined a free, global open and online course. You have a grade book, autograded assignments, discussion forums, and can earn badges for your efforts.

We take your privacy seriously on this site, you can review our Privacy Policy for more details.

If you want to use these materials in your own classes you can download or link to the artifacts on this site, export the course material as an IMS Common Cartridge®, or apply for an IMS Learning Tools Interoperability® (LTI®) key and secret to launch the autograders from your LMS.

The code for this site including the autograders, slides, and course content is all available on GitHub . That means you could make your own copy of the course site, publish it and remix it any way you like. Even more exciting, you could translate the entire site (course) into your own language and publish it. I have provided some instructions on how to translate this course in my GitHub repository.

And yes, Dr. Chuck actually has a race car - it is called the SakaiCar . He races in a series called 24 Hours of Lemons .

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Coursera - Python for everybody - ex 5.2

For the following problem: Write a program that repeatedly prompts a user for integer numbers until the user enters done . Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Input Cases: Enter 7, 2, bob, 10, and 4 and match the output below.

My program is not correctly showing the ans. What is problem here?

Output: Invalid input, Maximum is 10, Minimum is 2.

Output of the program

  • Suggestion: don't test only with the given sequence of inputs. Try a variety of test cases. For example, try entering only "done", try entering only one number, try entering only an invalid input, try entering numbers that only increase or decrease. When a test fails, fix the script for that case and then test some more. –  Dennis Sparrow Commented Jun 10, 2020 at 3:11
  • 1 Your indentation is off, everything in the while loop should be indented from the while True statement –  Sam Commented Jun 10, 2020 at 3:48
  • Looks to me like Maximum is 10, Minimum is 2 is correct, for 7, 2, bob, 10, 4. No? –  Sam Commented Jun 10, 2020 at 3:50
  • given output section is only the expected output. but my given input does not showup like that. –  user3404895 Commented Jun 10, 2020 at 3:55

10 Answers 10

You are missing out few statements while printing the output. The following code worked for me.

Have verified and runs successfully.

Harshit Ruwali's user avatar

  • Your answer is good, but code-only answers are discouraged. Please edit it to include an explanation. –  Sylvester is on codidact.com Commented Jan 1, 2022 at 21:58

Try this code and thank me later

Harrison Ofordu's user avatar

If you include elif statements, they won't be checked if the condition in the if statement is true, so if I had "elif smallest..." it would never be checked giving 'Minimus is none' as a result.

Y.B's user avatar

This is the only thing I could work out. Couldn't figure out how to keep largest and smallest at the value of none

lepsch's user avatar

Fellow coders; most of the above-provided codes are right. The problem is the browser. I used chrome and got a mismatch. I then run the same code using Microsoft edge and finally received "Grade updated on server." So use a different browser. thank me later.

wizzy's user avatar

  • Your answer could be improved with additional supporting information. Please edit to add further details about your code. –  CreepyRaccoon Commented May 4, 2023 at 11:44

Niqua's user avatar

  • I’m having trouble understanding your question, what exactly are you trying to ask? –  surftijmen Commented Dec 27, 2021 at 8:54

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged python python-3.8 or ask your own question .

  • The Overflow Blog
  • From PHP to JavaScript to Kubernetes: how one backend engineer evolved over time
  • Featured on Meta
  • We've made changes to our Terms of Service & Privacy Policy - July 2024
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...

Hot Network Questions

  • Miracle Miracle Octad Generator Generator
  • Vector of integers such that almost all dot products are positive
  • What does "close" mean in the phrase: "close a tooth pick between the jamb and the door"?
  • How to ensure a BSD licensed open source project is not closed in the future?
  • Is there racial discrimination at Tbilisi airport?
  • Book about a colony ship making an unscheduled stop in a star system with no habitable planets
  • "apt install emacs" linuxmint22 requires a mail system
  • If physics can be reduced to mathematics (and thus to logic), does this mean that (physical) causation is ultimately reducible to implication?
  • Melee Opportunist--making opportunity attacks have some bite for melee characters
  • Virtualbox stopped working (Package has no installation candidate)
  • What's the Matter?
  • How to extract code into library allowing changes without workflow overhead
  • Group automorphism fixing finite-index subgroup
  • "Authorized ESTA After Incorrectly Answering Criminal Offense Question: What Should I Do?"
  • How do you hide an investigation of alien ruins on the moon during Apollo 11?
  • Video game where the hero gets transported to another world with his sister to aid a king in a war
  • If Miles doesn’t consider Peter’s actions as hacking, then what does he think Peter is doing to the computer?
  • Is it possible to approximately compile Toffoli using H and CSWAP?
  • Flight left while checked in passenger queued for boarding
  • Is the error in translation of Genesis 19:5 deliberate?
  • Idiomatic alternative to “going to Canossa”
  • In the US, can I buy iPhone and Android phones and claim them as expense?
  • How to determine if a set is countable or uncountable?
  • Can figere come with a dative?

assignment 7 2 python for everybody

Python Forum

  • View Active Threads
  • View Today's Posts
  • View New Posts
  • My Discussions
  • Unanswered Posts
  • Unread Posts
  • Active Threads
  • Mark all forums read
  • Member List
  • Interpreter

Python for Everybody 5.2 assignment

  • Python Forum
  • Python Coding
  • 2 Vote(s) - 4 Average

Unladen Swallow
Oct-07-2017, 03:58 PM This is the Desired output:
Invalid input
Maximum is 10
Minimum is 2


This is my output:
7 ← Mismatch
2
bob
Please, enter only numbers.
10
4
Maximum 10
Minimum 2


I need help please.
Silly Frenchman

Oct-07-2017, 04:39 PM
Unladen Swallow
Oct-07-2017, 04:51 PM Lux Wrote: What's wrong with the output you're getting?
Check out my screenshot below:



I'm stumped. I'm tried everything I know to no avail. Desperately need some help on this.

Thank you all!
Silly Frenchman

Oct-07-2017, 04:56 PM seems to be why it's printing all the numbers- not sure if it's supposed to do that.
Unladen Swallow
Oct-07-2017, 05:08 PM

Thanks again for your time.
Silly Frenchman

Oct-07-2017, 05:12 PM (This post was last modified: Oct-07-2017, 05:12 PM by .) " instead of just "Maximum".
Unladen Swallow
Oct-07-2017, 05:14 PM
Unladen Swallow
May-31-2018, 04:22 PM
Unladen Swallow
Dec-12-2019, 05:12 PM This is the Desired output: Invalid input Maximum is 10 Minimum is 2 This is my output: 7 ← Mismatch 2 bob Please, enter only numbers. 10 4 Maximum 10 Minimum 2 I need help please.
Unladen Swallow
Apr-07-2020, 05:37 AM
  46,682 Jan-23-2021, 06:27 AM
:
  13,656 Oct-22-2020, 11:57 AM
:
  12,433 Jul-15-2020, 04:54 PM
:
  5,431 Jun-06-2020, 08:59 AM
:
  6,523 May-02-2020, 01:34 AM
:
  32,320 Apr-08-2020, 06:49 AM
:
  8,881 Dec-23-2019, 08:41 PM
:
  8,862 Oct-22-2019, 08:08 AM
:
  16,310 Jan-17-2019, 07:34 AM
:
  • View a Printable Version

User Panel Messages

Announcements.

assignment 7 2 python for everybody

Login to Python Forum

Get the Reddit app

Subreddit for posting questions and asking for general advice about your python code.

An issue with Assignment 5.2 [Coursera Programming for Everybody]

Even if my code matches desired output, it shows the code is incorrect. I spent all day trying to fix the issue but failed. Could anyone please help me fix the issue?

Screenshot: https://prnt.sc/1fs2vr8

By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .

Enter the 6-digit code from your authenticator app

You’ve set up two-factor authentication for this account.

Enter a 6-digit backup code

Create your username and password.

Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.

Reset your password

Enter your email address or username and we’ll send you a link to reset your password

Check your inbox

An email with a link to reset your password was sent to the email address associated with your account

Choose a Reddit account to continue

IMAGES

  1. GitHub

    assignment 7 2 python for everybody

  2. Python For Everybody (All the Solved Exercises

    assignment 7 2 python for everybody

  3. Python Data Structures Assignment 7.2 Solution [Coursera]

    assignment 7 2 python for everybody

  4. Programming for Everybody (Getting Started with Python)

    assignment 7 2 python for everybody

  5. [PDF] Download Python for Everybody by Charles Severance Book pdf

    assignment 7 2 python for everybody

  6. GitHub

    assignment 7 2 python for everybody

COMMENTS

  1. python-for-everybody/wk7

    wk7 - assignment 7.2.py. Cannot retrieve latest commit at this time. 7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values ...

  2. Python For Everybody Assignment 7.2

    Code link: https://drive.google.com/file/d/1h7guoz8JG5DsrRyBNQXygDSGONrW9gvc/view?usp=sharingCoursera: Python For Everybody Assignment 7.2 program solution |...

  3. Python Data Structures Assignment 7.2 Solution [Coursera ...

    Python Data Structures Assignment 7.2 Solution [Coursera] | Assignment 7.2 Python Data StructuresCoursera: Programming For Everybody Assignment 7.2 program s...

  4. Python for Everybody Answers

    The video is about the solution of the mentioned assignment of the python course named 'PYTHON FOR EVERYBODY' on coursera by Dr. Chuck

  5. [Coursera] Python for everybody 5.2 Assignment · GitHub

    Fork 5 5. [Coursera] Python for everybody 5.2 Assignment. Raw. 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try,except and put out an appropriate ...

  6. python_for_everybody/DataStructure/Assignment 7.2.py at master ...

    This repository contains my work while completing the specialization created by University of Michigan on Coursera. This Specialization builds on the success of the Python for Everybody course and will introduce fundamental programming concepts including data structures, networked application program interfaces, and databases, using the Python programming language.

  7. PY4E

    Python for Everybody. This web site is building a set of free materials, lectures, book and assignments to help students learn how to program in Python. You can take this course and receive a certificate at: Coursera: Python for Everybody Specialization; edX: Python for Everybody; FreeCodeCamp

  8. Coursera

    Try a variety of test cases. For example, try entering only "done", try entering only one number, try entering only an invalid input, try entering numbers that only increase or decrease. When a test fails, fix the script for that case and then test some more. Looks to me like Maximum is 10, Minimum is 2 is correct, for 7, 2, bob, 10, 4.

  9. sersavn/coursera-python-for-everybody-specialization

    Current repository contains all assignments, notes, quizzes and course materials from the "Python for Everybody Specialization" provided by Coursera and University of Michigan. Topics. html json sqlite python3 beautifulsoup urllib Resources. Readme Activity. Stars. 151 stars Watchers. 11 watching Forks. 85 forks

  10. "Python for Everybody" Chapter 7

    Order the book on Amazon: https://amzn.to/3huCub6If you want to support the channel, any donation in PayPal helps: https://bit.ly/2Ss5i90In this video, I am ...

  11. Coursera Programming for Everybody (Getting Started with Python) Week 7

    Subreddit for posting questions and asking for general advice about your python code. Members Online • Aman025 . Coursera Programming for Everybody (Getting Started with Python) Week 7 Assignment 5.2 . Ques: Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. ... Enter 7, 2, bob, 10, and 4 and ...

  12. Python for Everybody 5.2 assignment

    Joined: Oct 2017. Reputation: 1. #1. Oct-07-2017, 03:58 PM. Hey guys- I'm on my last assignment for Python and I need some expert assistance please. This is the assignment: 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers.

  13. Coursera-PY4E-Python-Data-Structures/Assignment-7.2 at master ...

    Contribute to riya2905/Coursera-PY4E-Python-Data-Structures development by creating an account on GitHub. ... Enterprise-grade 24/7 support Pricing; Search or jump to... Search code, repositories, users, issues, pull requests... Search Clear. Search syntax tips

  14. An issue with Assignment 5.2 [Coursera Programming for Everybody]

    An issue with Assignment 5.2 [Coursera Programming for Everybody] Even if my code matches desired output, it shows the code is incorrect. I spent all day trying to fix the issue but failed. Could anyone please help me fix the issue? Screenshot: https://prnt.sc/1fs2vr8. Also, as an aside, run your program with one number then "done." Even if my ...

  15. Coursera Python for everybody Assignments 7.1 and 7.2

    The above video consists of the images of the Assignment 7.1 and 7.2 of the course Python for everybody, the code was programmed on the auto-grader whose scr...

  16. Assignment 5.2

    CourseraProgramming for Everybody (Getting Started with Python)Week 5 Assignment 5.2 Question: 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it…

  17. Assignment solutions for python for everybody

    Python 100.0%. Assignment solutions for python for everybody. Contribute to sweehors/python-for-everybody development by creating an account on GitHub.

  18. GitHub

    If the file ends with _p2, this means that the file runs on Python 2. If the file ends with _p3, this means that the file runs on Python 3. I tried to create two versions. However, you can easily modify the syntax accordingly. Mostly it's due to the print syntax.

  19. Coursera Python for Everybody EP-13

    Hi guys, in this video I solved the assignment 5.2 of Coursera Python for Everybody. Hope you find it useful.If you're new, Subscribe! https://www.youtube....

  20. Python-For-Everybody-Specialization/Course-1-Getting-Started-With

    Saved searches Use saved searches to filter your results more quickly

  21. Python for Everybody Answers

    The video is about the solution of the mentioned assignment of the python course named 'PYTHON FOR EVERYBODY' on coursera by Dr. Chuck

  22. NPTEL Assignment Answers 2024 with Solutions (July-Dec)

    NPTEL Assignment Answers and Solutions 2024 (July-Dec). Get Answers of Week 1 2 3 4 5 6 7 8 8 10 11 12 for all courses. This guide offers clear and accurate answers ...