• 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
  • At scale, anything that could fail definitely will
  • Best practices for cost-efficient Kafka clusters
  • Featured on Meta
  • Announcing a change to the data-dump process
  • 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...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Strange variable scope behavior when calling function recursivly
  • Asked to suggest referees 9 months after submission: what to do?
  • Expensive constructors. Should they exist? Should they be replaced?
  • Is it possible to recover from a graveyard spiral?
  • When did graduate student teaching assistants become common in universities?
  • Using rule-based symbology for overlapping layers in QGIS
  • "The earth was formless and void" Did the earth exist before God created the world?
  • Can Christian Saudi Nationals visit Mecca?
  • In roulette, is the frequency of getting long sequences of reds lower than that of shorter sequences?
  • Why do proofs using continuity use the Bolzano-Weierstrass theorem?
  • Movie from 80s or 90s about a helmet which allowed to detect non human people
  • How do I learn more about rocketry?
  • What should I do if my student has quarrel with my collaborator
  • If I am to use midi keyboard only, do I still need audio interface?
  • What does "if you ever get up this way" mean?
  • What's "the archetypal book" called?
  • Does a representation of the universal cover of a Lie group induce a projective representation of the group itself?
  • Does proficiency with an ability check that uses a tool but not with the tool itself give any advantages for D&D 5.24?
  • Why is notation in logic so different from algebra?
  • Does it make sense for the governments of my world to genetically engineer soldiers?
  • Whats the safest way to store a password in database?
  • What other marketable uses are there for Starship if Mars colonization falls through?
  • Second Derivative for Non standard Calculus
  • How would you slow the speed of a rogue solar system?

assignment 5.2 python for everybody

Instantly share code, notes, and snippets.

@jmangrad

jmangrad / Exercise 5.2 - Python for Everybody

  • Download ZIP
  • Star ( 1 ) 1 You must be signed in to star a gist
  • Fork ( 0 ) 0 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 jmangrad/8aa25d1cd21b564eb0457114441e5d8b to your computer and use it in GitHub Desktop.
Write another program that prompts for a list of numbers
as above and at the end prints out both the maximum and minimum of
the numbers instead of the average.
largest = None
smallest = None
count = 0
total = 0
while True:
try:
number = input("Enter a number: ")
if number == "done":
break
number = int(number)
count +=1
total =number + total
if largest == None and smallest == None:
largest = number
smallest = number
if largest == None or number > largest:
largest = number
if smallest == None or number < smallest:
smallest = number
except:
print("Invalid input")
print("The maximum number is: {}".format(largest))
print("The minimum number is: {}".format(smallest))
print("The total number is: {}".format(total))
print("The count number is: {}".format(count))

@Edeath-9

Edeath-9 commented Mar 25, 2022

I have written this code but in case of largest and smallest number it is showing done. How to fix this

Sorry, something went wrong.

@newbie-Ds

newbie-Ds commented Jun 7, 2022 • edited Loading

I think it's because you put while True: number = input("Enter a Number: ") largest = number ------------------ if you enter 'done', here returns to 'done' smallest = number ------------------ if you enter 'done', here returns to 'done'

Let's try if this works.

@kholoud24

kholoud24 commented Aug 5, 2022

maxum = False minum = False while True: input_value = input("enter number\n") if input_value == 'done': break try: input_value = int(input_value) if not maxum or maxum < input_value: maxum = input_value

print('max is ', maxum, 'min is', minum)

@Minting-2022

Minting-2022 commented Nov 9, 2022

When I enter a number,it just shows the'Invalid input',how can I fix it? count=0 total=0 largest=None smallest=None

while True: number=input("Enter a number: ") if number=='done': break try: fnum=float(number) if number=='done': break if largest<=fnum: largest=fnum if smallest>=fnum: smallest=fnum except: print("Invalid input") continue total=total+fnum count=count+1

print(total,count,largest,smallest)

@gaurvimadan

gaurvimadan commented Nov 13, 2022 • edited Loading

I guess the problem is that you have used below mentioned if statement twice. It shouldn't be added in try statement. if number=='done': break

I tried solving the question in the below mentioned way, maybe it can help you.

When I enter a number,it just shows the'Invalid input',how can I fix it? count=0 total=0 largest=None smallest=None while True: number=input("Enter a number: ") if number=='done': break try: fnum=float(number) if number=='done': break if largest<=fnum: largest=fnum if smallest>=fnum: smallest=fnum except: print("Invalid input") continue total=total+fnum count=count+1 print(total,count,largest,smallest)

@marzth23

marzth23 commented May 25, 2024

I did mine like this, I hope it helps...

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,791 Jan-23-2021, 06:27 AM
:
  13,725 Oct-22-2020, 11:57 AM
:
  12,458 Jul-15-2020, 04:54 PM
:
  5,468 Jun-06-2020, 08:59 AM
:
  6,567 May-02-2020, 01:34 AM
:
  32,406 Apr-08-2020, 06:49 AM
:
  8,910 Dec-23-2019, 08:41 PM
:
  8,898 Oct-22-2019, 08:08 AM
:
  16,343 Jan-17-2019, 07:34 AM
:
  • View a Printable Version

User Panel Messages

Announcements.

assignment 5.2 python for everybody

Login to Python Forum

assignment 5.2 python for everybody

  • Table of Contents
  • Course Home
  • Assignments
  • Peer Instruction (Instructor)
  • Peer Instruction (Student)
  • Change Course
  • Instructor's Page
  • Progress Page
  • Edit Profile
  • Change Password
  • Scratch ActiveCode
  • Scratch Activecode
  • Instructors Guide
  • About Runestone
  • Report A Problem
  • Functions with Tuples and Dictionaries Mixed-Up Code Questions
  • Functions and Conditionals Mixed-Up Code Questions
  • Mixed-up Code Questions
  • Functions and Lists Mixed-Up Code Questions
  • Function and String Mixed-Up Code Questions
  • Please join a research study to help us test new approaches to learning programming!
  • Functions and Loops Mixed-Up Code Questions
  • Functions Mixed-Up Code Questions
  • Practice Problems
  • An Introduction To Our System
  • Self-efficacy Post-Survey
  • Peer Instruction: Function Multiple Choice Questions
  • Peer Instruction: Functions Multiple Choice Questions
  • 5.1 Function calls
  • 5.2 Built-in functions
  • 5.3 Type conversion functions
  • 5.4 Math functions
  • 5.5 Random numbers
  • 5.6 Adding new functions
  • 5.7 Definitions and uses
  • 5.8 Flow of execution
  • 5.9 Parameters and arguments
  • 5.10 Fruitful functions and void functions
  • 5.11 Why functions?
  • 5.12 Debugging
  • 5.13 Glossary
  • 5.14 Multiple Choice Questions
  • 5.15 Mixed-up Code Questions
  • 5.16 Write Code Questions
  • 5.17 Group Work: Functions
  • 5.18 Functions Multiple Choice Questions
  • 5.19 Functions Mixed-Up Code Questions
  • 5.20 Functions Write Code Questions
  • 5.21 Group Work: Functions and Strings
  • 5.22 Functions and Strings Multiple Choice Questions
  • 5.23 Functions and Strings Mixed-Up Code Questions
  • 5.24 Functions and Strings Write Code Questions
  • 5.25 Group Work: Functions and Conditionals
  • 5.26 Functions and Conditionals Multiple Choice Questions
  • 5.27 Functions and Conditionals Mixed-Up Code Questions
  • 5.28 Functions and Conditionals Write Code Questions
  • 5.29 Group Work: Functions and Lists
  • 5.30 Functions with Lists Multiple Choice Questions
  • 5.31 Functions and Lists Mixed-Up Code Questions
  • 5.32 Functions and Lists Write Code Questions
  • 5.33 Group Work: Functions with Loops
  • 5.34 Functions with Loops Multiple Choice Questions
  • 5.35 Functions and Loops Mixed-Up Code Questions
  • 5.36 Functions and Loops Write Code Questions
  • 5.37 Group Work: Functions with Tuples and Dictionaries
  • 5.38 Functions with Tuples and Dictionaries Multiple Choice Questions
  • 5.39 Functions with Tuples and Dictionaries Mixed-Up Code Questions
  • 5.40 Functions with Tuples and Dictionaries Write Code Questions
  • 5.41 Group Work: Functions, Strings, and Conditionals
  • 5.42 Group Work: Functions with Lists and Loops
  • 5.43 Homework: Creating Functions from Sample Input and Output
  • 5.44 Discussion: Creating Functions from Sample Input and Output
  • 5.1. Function calls" data-toggle="tooltip">
  • 5.3. Type conversion functions' data-toggle="tooltip" >

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

5.2. Built-in functions ¶

Python provides a number of important built-in functions that we can use without needing to provide the function definition. The creators of Python wrote a set of functions to solve common problems and included them in Python for us to use.

The max and min functions give us the largest and smallest values in a list, respectively:

The max function gives us the value 4 because it is the largest value in the list. The min function, inversely, give us the value -2 because it is the smallest value in the list.

Q-2: What will be printed as the output of this code?

  • Incorrect! You cannot use the max function to compare different data types. Try again.
  • There is an error
  • Correct! This code causes a TypeError because the max function cannot be used to compare different data types.

Another very common built-in function is the len function, which tells us how many items are in its argument. If the argument to len is a string, it returns the number of characters in the string.

These functions can operate on any set of values, as we will see in later chapters.

You should treat the names of built-in functions as reserved words (i.e., avoid using “max” as a variable name).

Activity: CodeLens 5.2.4 (functBuiltin_codelens_line2)

Q-5: Consider the code block below. What prints?

  • Incorrect! Spaces and punctuation characters count in the length. Try again.
  • Incorrect! Punctuation characters count in the length. Try again.
  • Incorrect! Spaces count in the length. Try again.
  • Correct! 13 is the length of all characters in the string, including spaces and punctuation.

Q-6: Which of the following would work as a variable name?

  • Incorrect! This is a reserved keyword because it is a built-in function in Python. Try again.
  • Correct! built_in is a valid variable name because it is not a built-in Python function.

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. [Coursera] Python for everybody 5.2 Assignment · GitHub

    assignment 5.2 python for everybody

  2. Coursera

    assignment 5.2 python for everybody

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

    assignment 5.2 python for everybody

  4. Coursera Python For Everybody Assignment 5 2 Program Solution

    assignment 5.2 python for everybody

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

    assignment 5.2 python for everybody

  6. "Python for Everybody" Chapter 5

    assignment 5.2 python for everybody

VIDEO

  1. Python for Everybody Full University Python Course 1

  2. 1-Welcome to the Course (Getting Start with Python)

  3. python assignment operator

  4. Coursera Assignment 2.3 Solved Python for Everybody

  5. How to use Assignment Operators in python

  6. Top 50 Python for Everybody Specialization Interview Questions &Answers #python #pythonforeverybody

COMMENTS

  1. Coursera

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

  2. 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....

  3. python-for-everybody/wk5

    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 message and ignore the number.

  4. Python For Everybody Assignment 5.2 solution

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

  5. 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

  6. 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. - sersavn/coursera-python-for-everybody-specialization

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

    [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 message ...

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

    [Coursera] Python for everybody 5.2 Assignment. GitHub Gist: instantly share code, notes, and snippets.

  9. Help with the assignment 5.2 in Python for everybody

    Community Support (Archived) — Edward Lundqvist asked a question. March 8, 2021 at 6:45 AM. Help with the assignment 5.2 in Python for everybody. I need help with the assignment 5.2 in Python for everybody. Somebody that could help me?

  10. Exercise 5.2

    Star 1 1. Fork 0 0. Raw. Exercise 5.2 - Python for Everybody. Write another program that prompts for a list of numbers. as above and at the end prints out both the maximum and minimum of. the numbers instead of the average. largest = None.

  11. Coursera: Python For Everybody Assignment 5.2 program ...

    Coursera: Programming For Everybody Assignment 5.2 program solution Answer | Python for Everybody Assignment 5.2 program solution.IF YOUR PROGRAM IS WORKING...

  12. 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…

  13. GitHub

    This contains all the practices for the lectures, custom answers to the assignments and additional inline notes for "Python for Everybody Specialization" on Coursera by the University of Michigan. 42 stars 55 forks Branches Tags Activity

  14. Coursera Python Assignment 5.2 : r/learnpython

    The assignment is. 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 message and ignore the number.

  15. 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.

  16. 5.2. Built-in functions

    Activity: 5.2.3 The len function tells us how many items are in its argument. (functBuiltin_len) These functions can operate on any set of values, as we will see in later chapters. You should treat the names of built-in functions as reserved words (i.e., avoid using "max" as a variable name). 1. city_name = "Detroit".

  17. Python-For-Everybody-Specialization/Course-1-Getting-Started ...

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window.

  18. 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 ...

  19. EngineerInd/Coursera-Python-for-everybody-solutions

    Hello friends, In this video we discussed about Coursera programming for everybody Assignment 5.2 answer other way it's known as Python for everybody Exercise 5.2 Complete program In this course Assignment (Exercise) are available in week 7 part.