Python for Everybody

Exercise 12.3, exercise 12.4, exercise 12.5.

  • 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
  • The hidden cost of speed
  • The creator of Jenkins discusses CI/CD and balancing business with open source
  • 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

  • how do I fix apt-file? - not working and added extra repos
  • What`s this? (Found among circulating tumor cells)
  • What would be a good weapon to use with size changing spell
  • help to grep a string from a site
  • Why are there both "was" and "wozu" in this sentence: "Auf jeden fall ist es mir vollkommen egal, was Sie denken, wozu Sie ein recht hätten!"?
  • Is my magic enough to keep a person without skin alive for a month?
  • What qualifies as a Cantor diagonal argument?
  • Investigate why packages are held back, and stop release upgrade
  • Children in a field trapped under a transparent dome who interact with a strange machine inside their car
  • What is the optimal number of function evaluations?
  • Sub-/superscript size difference between newtxmath and txfonts
  • A seven letter *
  • Direction of centripetal acceleration
  • Breaker trips when plugging into wall outlet(receptacle) directly, but not when using extension
  • Why didn't Air Force Ones have camouflage?
  • How high does the ocean tide rise every 90 minutes due to the gravitational pull of the space station?
  • Could a lawyer agree not to take any further cases against a company?
  • How can I play MechWarrior 2?
  • Does the average income in the US drop by $9,500 if you exclude the ten richest Americans?
  • Transform a list of rules into a list of function definitions
  • What is the translation of this quote by Plato?
  • Current in a circuit is 50% lower than predicted by Kirchhoff's law
  • Does a party have to wait 1d4 hours to start a Short Rest if no healing is available and an ally is only stabilized?
  • Enumitem + color labels + multiline = bug?

python for everybody assignment 12

python for everybody assignment 12

  • 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
  • Mixed-Up Code Questions
  • Practice Problems - Advanced Regular Expressions
  • Problem Bank for Practice Problems and Test Problems
  • Introduction to Problem Types
  • Practice Problems - Mixed-up Code
  • Practice Problems - Write Code
  • 12.1 Regular Expressions
  • 12.2 Character Matching in Regular Expressions
  • 12.3 Extracting Data Using Regular Expressions
  • 12.4 Combining Searching and Extracting
  • 12.5 Escape Character
  • 12.6 Summary
  • 12.7 Bonus section for Unix / Linux users
  • 12.8 Debugging
  • 12.9 Glossary
  • 12.10 Multiple Choice Questions
  • 12.11 Practice Problems - Regular Expressions
  • 12.12 Mixed-Up Code Questions
  • 12.13 Write Code Questions
  • 12.14 Group Work: Regular Expressions (Regex)
  • 12.15 Group Work: More Regular Expressions (Regex)
  • 12. Regular Expressions" data-toggle="tooltip">
  • 12.2. Character Matching in Regular Expressions' data-toggle="tooltip" >

12.1. Regular Expressions ¶

So far we have been reading through files, looking for patterns and extracting various bits of lines that we find interesting. We have been using string methods like split and find and using lists and string slicing to extract portions of the lines.

This task of searching and extracting is so common that Python has a very powerful library called regular expressions that handles many of these tasks quite elegantly. The reason we have not introduced regular expressions earlier in the book is because while they are very powerful, they are a little complicated and their syntax takes some getting used to.

Regular expressions are almost their own little programming language for searching and parsing strings. As a matter of fact, entire books have been written on the topic of regular expressions. In this chapter, we will only cover the basics of regular expressions. For more detail on regular expressions, see:

https://en.wikipedia.org/wiki/Regular_expression

https://docs.python.org/library/re.html

The regular expression library re must be imported into your program before you can use it. The simplest use of the regular expression library is the search() function. The following program demonstrates a trivial use of the search function.

This code uses regular expressions to print lines that contain “From:”.

We open the file, loop through each line, and use the regular expression search() to only print out lines that contain the string “From:”. This program does not use the real power of regular expressions, since we could have just as easily used line.find() to accomplish the same result.

11-9-2: Which of the following correctly imports the regex library?

  • import regex
  • The module name is not regex.
  • import re.search()
  • We are not importing a specific regex function.
  • Correct! This is the proper way to import the regular expression library.
  • import regular_expressions
  • This is not the module name. It is much shorter.

The power of the regular expressions comes when we add special characters to the search string that allow us to more precisely control which lines match the string. Adding these special characters to our regular expression allow us to do sophisticated matching and extraction while writing very little code.

For example, the caret character is used in regular expressions to match “the beginning” of a line. We could change our program to only match lines where “From:” was at the beginning of the line as follows:

Using regular expressions to print lines that contain “From:” at the beginning of the line.

Now we will only match lines that start with the string “From:”. This is still a very simple example that we could have done equivalently with the startswith() method from the string library. But it serves to introduce the notion that regular expressions contain special action characters that give us more control as to what will match the regular expression.

11-9-4: Which lines will the following code print?

  • Any line that contains a 'B'
  • Regular expressions are case sensitive for individual characters.
  • Any line containing a 'b'
  • Correct! Since there is no ^ before the 'b', we are only looking at lines that contain the letter 'b'.
  • Lines that start with the letter 'b'
  • Since there is no ^, we are only looking for lines that contain 'b', not those that start with 'b'.
  • Lines that contain 'B' or 'b'
  • Regular expressions are case sensitive for individual characters, so it will only look for 'b'.

Construct a block of code that loops reading lines from a file, removes whitespace on the right of the line, and prints out any line starting with ‘Wolverines’.

Python for Everybody

The goal of this book is to provide an Informatics-oriented introduction to programming. The primary difference between a computer science approach and the Informatics approach taken in this book is a greater focus on using Python to solve data analysis problems common in the world of Informatics.

The sample code and data files for the book is here: Code Samples .

Other courses / web sites using this book

Book translations:

  • Printed book on Amazon India (low-cost shipping within India thanks to Shroff Publishing )
  • Kindle edition of the book
  • Free: PDF , HTML , EPUB
  • HTML with examples in Jupyter Notebooks from LibreTexts.org
  • Download HTML in a ZIP (~6MB)
  • Interactive HTML from Trinket.io
  • Translated book, autograders, resources, and web site at https://es.py4e.com
  • Github repo - Contributors: Juan Carlos Perez Castellanos , Juan Dougnac , Daniel Merino Echeverría , Jaime Bermeo Ramírez and Fernando Tardío .
  • Free PDF , EPUB
  • Book source on github , (Thanks to Alessandro Rossetti and Vittore Zen )
  • Free: PDF , EPUB
  • Book source on github and translation team (Thanks to Yuri Loia de Medeiros ).
  • Polish verson of web site - py4e.pl
  • HTML , PDF (format A4) , PDF (format for print) , EPUB , MOBI
  • Github Repository
  • Contributors: Andrzej Wójtowicz (Adam Mickiewicz University in Poznań, Poland)
  • Greek version of the web site - gr.py4e.com
  • Printed Book
  • Free PDF (in progress): PDF
  • Github repository
  • Thanks to: Konstantia Kiourtidou
  • Free: PDF Book
  • Translation by: Electronics Go | Team members
  • DMK Press is working on a commercial translation of the book and will provide a free PDF for this site when it is completed.
  • Russian versions of the slides from Violetta Fomkina .
  • Korean (commercial translation) 데이터를 다루며 배우는 파이썬
  • Book source on github - (Thanks to Deng Luo)
  • There is an in-China copy of the videos available at https://www.bilibili.com/video/av46649799

If you are insterested in starting a translation of the book, I have some instructions for getting started .

Chapters 2-10 are heavily adapted from the open book titled: " Think Python: How to Think like a Computer Scientist " by Allen B. Downey and Jeff Elkner . The Python 2 version of the book is still available.

Copyright Creative Commons Attribution 3.0 - Charles R. Severance

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

this contains all the answers to the quizes and asssignments for "Programming for Everybody (Getting Started with Python)" on Coursera by the University of Michigan.

Ritik2703/Coursera---Programming-for-Everybody-Getting-Started-with-Python-

Folders and files.

NameName
23 Commits

Repository files navigation

Coursera---programming for everybody (getting started with python).

  • Roff 100.0%

IMAGES

  1. "Python for Everybody" Chapter 12

    python for everybody assignment 12

  2. Programming for Everybody (Getting Started with Python)

    python for everybody assignment 12

  3. Coursera: Python For Everybody Complete Course Assignments Solution |Python For Everybody Assignment

    python for everybody assignment 12

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

    python for everybody assignment 12

  5. Python for Everybody Specialization

    python for everybody assignment 12

  6. GitHub

    python for everybody assignment 12

VIDEO

  1. Assignment

  2. What should I use instead of assignment-in-an-expression in Python? #shorts

  3. Python for Everybody Full University Python Course 1

  4. Assignment

  5. Assignment 9.4 Python Data Structures

  6. "Python for Everybody" Chapter 12

COMMENTS

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

  2. Python For Everybody (All the Solved Exercises

    Order the book on Amazon: https://amzn.to/3huCub6If you want to support the channel, any donation in PayPal helps: https://bit.ly/2Ss5i90Follow me on Faceboo...

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

    sersavn/coursera-python-for-everybody-specialization

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

  5. "Python for Everybody" Chapter 12

    Order the book on Amazon: https://amzn.to/3huCub6Follow me on Facebook: https://www.facebook.com/aksonaiInstagram: https://www.instagram.com/akson.aiTwitter:...

  6. Projects

    """ Exercise 12.3: Use urllub to replicate the previous exercise of (1) retrieving the document from a URL, (2) displaying up to 3000 characters, ... simply show the first 3000 characters of the document contents. Python for Everybody: Exploring Data Using Python 3 by Charles R. Severance Solution by Jamison Lahman, June 4, ...

  7. Python for Everyone

    Find step-by-step solutions and answers to Python for Everyone - 9781119056553, as well as thousands of textbooks so you can move forward with confidence. ... Chapter 12:Sorting And Searching. Page 685: Review Exercises. Page 688: Programming Exercises. Exercise 1. Exercise 2. Exercise 3a. Exercise 3b. Exercise 3c. Exercise 3d. Exercise 3e ...

  8. PY4E

    PY4E - Python for Everybody

  9. Python for Everybody

    Interactive — Python for Everybody

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

  11. jmelahman/python-for-everybody-solutions

    Solutions to Python for Everybody: Exploring Data using Python 3 by Charles Severance - jmelahman/python-for-everybody-solutions

  12. "Python for Everybody" Chapter 12

    Order the book on Amazon: https://amzn.to/3huCub6If you want to support the channel, any donation in PayPal helps: https://bit.ly/2Ss5i90Here is the missing ...

  13. Python for Everybody

    Python for Everybody (PY4E) ... We look at Python's simplest data structure - the list. Lists can store more than one item in a variable. 10: Dictionaries ... up the values by their key. 11: Tuples The tuple is a Python data structure that is like a simple and efficient list. 12: Regular Expressions

  14. Python for Everybody

    Assignments in this module: 5; Discussions in this module: 1; Object-Oriented Programming. Resources in this module: 6; Assignments in this module: 1; Discussions in this module: 1; Databases. Resources in this module: 13; Assignments in this module: 7; Discussions in this module: 1; Data Visualization. Resources in this module: 12; Discussions ...

  15. Programming for Everybody (Getting Started with Python)

    There are 7 modules in this course. This course aims to teach everyone the basics of programming computers using Python. We cover the basics of how one constructs a program from a series of simple instructions in Python. The course has no pre-requisites and avoids all but the simplest mathematics. Anyone with moderate computer experience should ...

  16. PYTHON-FOR-EVERYBODY/CHAPTER 12 exercises.ipynb at master ...

    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.

  17. Python for Everybody

    PY4E - Python for Everybody. Chapter 1: Introduction Chapter 2: Variables Chapter 3: Conditionals Chapter 4: Functions Chapter 5: Iterations Chapter 6: Strings Chapter 7: Files Chapter 8: Lists Chapter 9: Dictionaries Chapter 10: Tuples Chapter 11: Regex Chapter 12: Networked Programs Chapter 13: Python and Web Services Chapter 14: Python ...

  18. 12.1. Regular Expressions

    7. Activity: 12.1.1 ActiveCode (re_ac1) We open the file, loop through each line, and use the regular expression search() to only print out lines that contain the string "From:". This program does not use the real power of regular expressions, since we could have just as easily used line.find() to accomplish the same result.

  19. Programming for Everybody (Getting Started with Python)

    Programming for Everybody (Getting Started with Python)

  20. Solutions to the exercises of the popular Python specialisation in

    Solutions to the exercises of the popular Python specialisation in Coursera offered by the University of Michigan and taught by Dr. Chuck. This repository contains the solutions of the assignments of all 5 courses in the specialisation: 1.Programming for Everybody (Getting started with Python) 2.Python Data Structures 3.Using Python to Access Web Data 4.Using Databases with Python 5.Capstone ...

  21. Python for Everybody

    PY4E - Python for Everybody

  22. Python for Everybody Specialization

    Specialization - 5 course series. 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. In the Capstone Project, you'll use the technologies ...

  23. Ritik2703/Coursera---Programming-for-Everybody-Getting-Started-with-Python-

    this contains all the answers to the quizes and asssignments for "Programming for Everybody (Getting Started with Python)" on Coursera by the University of Michigan. - Ritik2703/Coursera---Programming-for-Everybody-Getting-Started-with-Python-