Instantly share code, notes, and snippets.

@jmangrad

jmangrad / Exercise 2.3 - Python for Everybody

  • Download ZIP
  • Star ( 0 ) 0 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/bf055b745fca9574c2e3f28ca018212f to your computer and use it in GitHub Desktop.
Exercise 3: Write a program to prompt the user for hours and rate per
hour to compute gross pay.
Enter Hours: 35
Enter Rate: 2.75
Pay: 96.25
hours = int(input("Enter hours worked: ")) # asks for hours worked in int
rate = float(input("Enter rate: ")) # asks for rate in float
pay = hours * rate # calculates total pay for the hours worked
print("Pay = {}".format(pay))

python for everybody coursera assignment 2.3

  • 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
  • This Chapter
  • 1. Why Program?' data-toggle="tooltip" >

Python for Everybody - Interactive ¶

Assignments ¶, table of contents ¶.

  • 1.1. Why should you learn to write programs?
  • 1.2. Creativity and motivation
  • 1.3. Computer hardware architecture
  • 1.4. Understanding programming
  • 1.5. Words and sentences in Python
  • 1.6. Conversing with Python
  • 1.7. Terminology: Interpreter and compiler
  • 1.8. Writing a program
  • 1.9. What is a program?
  • 1.10. The building blocks of programs
  • 1.11. What could possibly go wrong?
  • 1.12. Debugging
  • 1.13. The learning journey
  • 1.14. Glossary
  • 1.15. Exercises
  • 2.1. Values and types
  • 2.2. Variables
  • 2.3. Variable names and keywords
  • 2.4. Statements
  • 2.5. Operators and operands
  • 2.6. Expressions
  • 2.7. Order of operations
  • 2.8. Modulus operator
  • 2.9. String operations
  • 2.10. Asking the user for input
  • 2.11. Comments
  • 2.12. Choosing mnemonic variable names
  • 2.13. Debugging
  • 2.14. Glossary
  • 2.15. Multiple Choice Questions
  • 2.16. Mixed-up Code Questions
  • 2.17. Write Code Questions
  • 3.1. How to be a Successful Programmer
  • 3.2. How to Avoid Debugging
  • 3.3. Beginning tips for Debugging
  • 3.4.1. ParseError
  • 3.4.2. TypeError
  • 3.4.3. NameError
  • 3.4.4. ValueError
  • 3.5. Summary
  • 3.6. Exercises
  • 4.1. Boolean expressions
  • 4.2. Logical operators
  • 4.3. Conditional execution
  • 4.4. Alternative execution
  • 4.5. Chained conditionals
  • 4.6. Nested conditionals
  • 4.7. Catching exceptions using try and except
  • 4.8. Short-circuit evaluation of logical expressions
  • 4.9. Debugging
  • 4.10. Glossary
  • 4.11. Multiple Choice Questions
  • 4.12. Mixed-up Code Questions
  • 4.13. Write Code Questions
  • 4.14.1. Comparison Operators
  • 4.14.2. if/else Statements
  • 4.14.3. Boolean Operations
  • 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.1. Print and Function Basics
  • 5.17.2. Parts of a Function and Function Calls
  • 5.17.3. Writing Function Calls
  • 5.17.4. Function Order
  • 5.17.5. Special Characters and Keywords
  • 5.18. Functions Multiple Choice Questions
  • 5.19. Functions Mixed-Up Code Questions
  • 5.20. Functions Write Code Questions
  • 5.21.1. String Indices
  • 5.21.2. String Slices
  • 5.21.3. Input and Converting Between Strings and Numbers
  • 5.21.4. String Methods
  • 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.1. Basic Conditionals and Tests
  • 5.25.2. Logical Operators and Complex 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.1. List Indexing
  • 5.29.2. Built-in Functions That Work on Lists
  • 5.29.3. List Methods
  • 5.29.4. Using the Slice Operator
  • 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.1. The For-Each Loop
  • 5.33.2. Range and For
  • 5.33.3. While 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.1. Tuples
  • 5.37.2. Tuples are Immutable
  • 5.37.3. 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.1. Function Example
  • 5.41.2. String Definition
  • 5.41.3. String Indices
  • 5.41.4. String Slices
  • 5.41.5. Basic Conditionals and Tests
  • 5.41.6. Logical Operators and Complex Conditionals
  • 5.42.1. List Indexing and Slicing
  • 5.42.2. Built-in Functions That Work on Lists
  • 5.42.3. List Methods
  • 5.42.4. The For-Each Loop
  • 5.42.5. Range and For
  • 5.42.6. While Loops
  • 5.43.1. Function 1
  • 5.43.2. Function 2
  • 5.43.3. Function 3
  • 5.43.4. Function 4
  • 5.43.5. Extra Credit
  • 5.44.1. Function 1
  • 5.44.2. Function 2
  • 5.44.3. Function 3
  • 5.44.4. Function 4
  • 6.1. Updating variables
  • 6.2. The while statement
  • 6.3. Infinite loops
  • 6.4. Finishing iterations with continue
  • 6.5. Definite loops using for
  • 6.6.1. Counting and summing loops
  • 6.6.2. Maximum and minimum loops
  • 6.7. Debugging
  • 6.8. Glossary
  • 6.9. Multiple Choice Questions
  • 6.10. Mixed-up code Questions
  • 6.11. Write Code Questions
  • 6.12.1. for Statements
  • 6.12.2. The range Function
  • 6.12.3. while Statements
  • 7.1. A string is a sequence
  • 7.2. Getting the length of a string using len()
  • 7.3. Traversal through a string with a loop
  • 7.4. String slices
  • 7.5. Strings are immutable
  • 7.6. Looping and counting
  • 7.7. The in operator
  • 7.8. String comparison
  • 7.9. String methods
  • 7.10. Parsing strings
  • 7.11. Format operator
  • 7.12. Debugging
  • 7.13. Glossary
  • 7.14. Multiple Choice Questions
  • 7.15. Mixed-up Code Questions
  • 7.16. Write-code questions
  • 7.17.1. Indexing and Slicing
  • 7.17.2. Common String Methods
  • 8.1. Persistence
  • 8.2. Opening files
  • 8.3. Text files and lines
  • 8.4. Reading files
  • 8.5. Searching through a file
  • 8.6. Letting the user choose the file name
  • 8.7. Using try, except, and open
  • 8.8. Writing files
  • 8.9. Debugging
  • 8.10. Summary
  • 8.11. Glossary
  • 8.12. Multiple Choice Questions
  • 8.13. Mixed-up Code Questions
  • 8.14. Write Code Questions
  • 8.15.1. Reading from Files
  • 8.16.1. Comma-Separated Values (CSV) Files
  • 8.16.2. Nested dictionaries
  • 8.16.3. Comma-Separated Values (CSV) Files with a Header Row
  • 8.17.1. CSV Reader
  • 8.17.2. Reading Comma-Separated Values (CSV) Files with a Header Row
  • 8.17.3. Writing a Comma-Separated Values (CSV) File with CSV Writer
  • 9.1. A list is a sequence
  • 9.2. Lists are mutable
  • 9.3. Traversing a list
  • 9.4. List operations
  • 9.5. List slices
  • 9.6. List methods
  • 9.7. Deleting elements
  • 9.8. Lists and functions
  • 9.9. Lists and strings
  • 9.10. Parsing lines
  • 9.11. Objects and values
  • 9.12. Aliasing
  • 9.13. List arguments
  • 9.14. Debugging
  • 9.15. Glossary
  • 9.16. Multiple Choice Questions
  • 9.17. Mixed-Up Code Questions
  • 9.18. Write Code Questions
  • 9.19. Group Work: Lists
  • 10.1. Dictionaries
  • 10.2. Dictionary as a Set of Counters
  • 10.3. Dictionaries and Files
  • 10.4. Looping and Dictionaries
  • 10.5. Advanced Text Parsing
  • 10.6. Debugging
  • 10.7. Glossary
  • 10.8. Multiple Choice Questions
  • 10.9. Mixed-Up Code Questions
  • 10.10. Write Code Questions
  • 11.1. Tuples are Immutable
  • 11.2. Comparing Tuples
  • 11.3. Tuple Assignment
  • 11.4. Dictionaries and Tuples
  • 11.5. Multiple Assignment with Dictionaries
  • 11.6. The Most Common Words
  • 11.7. Using Tuples as Keys in Dictionaries
  • 11.8. Sequences: Strings, Lists, and Tuples - Oh My!
  • 11.9. Debugging
  • 11.10. Glossary
  • 11.11. Multiple Choice Questions
  • 11.12. Tuples Mixed-Up Code Questions
  • 11.13. Write Code Questions
  • 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.1. Regex Methods
  • 12.14.2. Quantifiers
  • 12.14.3. Character Sets
  • 12.14.4. Character Ranges
  • 12.14.5. Character Classes
  • 12.14.6. Escaping Special Characters
  • 12.14.7. Greedy and Non-Greedy Matching
  • 12.15.1. Using a logical “or”
  • 12.15.2. Specifying What to Extract - Matching Groups
  • 12.15.3. Specifying What to Extract - Non-Matching Groups
  • 12.15.4. Boundary or Anchor Characters
  • 12.15.5. Negating a Character Set
  • 13.1. Networked programs
  • 13.2. HyperText Transfer Protocol - HTTP
  • 13.3. The world’s simplest web browser
  • 13.4. Retrieving an image over HTTP
  • 13.5. Retrieving web pages with urllib
  • 13.6. Reading binary files using urllib
  • 13.7.1. Start and End Tags
  • 13.7.2. List Tags
  • 13.7.3. Tag Relationships: Parent, Child, Sibling
  • 13.8. Mixed-Up Code Questions
  • 13.9.1. Table Tags
  • 13.9.2. Link Tag
  • 13.9.3. Image Tag
  • 13.9.4. Attributes
  • 13.9.5. Div and Span tags
  • 13.9.6. Using CSS Classes
  • 13.10. Parsing HTML and scraping the web
  • 13.11. Parsing HTML using regular expressions
  • 13.12. Parsing HTML using BeautifulSoup
  • 13.13.1. Getting a tag from a soup object
  • 13.13.2. Getting text from a tag
  • 13.13.3. Getting data from tags with attributes
  • 13.13.4. How to Find Tags Inside of Tags
  • 13.14. Bonus section for Unix / Linux users
  • 13.15. Glossary
  • 13.16. Multiple Choice Questions
  • 13.17. Mixed-Up Code Questions
  • 13.18. Write Code Exercises
  • 14.1. Scrape all the Cottage Inn Pizza locations
  • 14.2. Get news links from faculty webpages
  • 14.3.1. Plan 2: Example
  • 14.3.2. Plan 2: When to use this plan
  • 14.3.3. Plan 2: How to use this plan
  • 14.3.4. Plan 2: Exercises
  • 14.4.1. Plan 3: Example
  • 14.4.2. Plan 3: When to use this plan
  • 14.4.3. Plan3: How to use this plan
  • 14.4.4. Plan 3: Exercises
  • 14.5.1. Plan 4: Example
  • 14.5.2. Plan 4: When to use it
  • 14.5.3. Plan 4: How to use it
  • 14.5.4. Plan 4: Exercises
  • 14.6.1. Looking closer at a tag
  • 14.6.2. Plan 5: Example
  • 14.6.3. Plan 5: How to use it
  • 14.6.4. Plan 5: Exercises
  • 14.7.1. Plan 9: Example
  • 14.7.2. Plan 9: Exercises
  • 14.8.1. Plan 10: Outline
  • 14.9. Code writing activity part 1
  • 14.10. Code writing activity part 2
  • 14.11. Code writing activity part 3
  • 14.12. Code debugging activity
  • 14.13.1. Relevant tags
  • 14.14.1. Plan 1
  • 14.14.2. Plan 2
  • 14.14.3. Plan 3
  • 14.14.4. Plan 4
  • 14.14.5. Plan 5
  • 14.14.6. Plan 6
  • 14.14.7. Plan 9
  • 14.14.8. Plan 10
  • 14.15. Multiple Choice Questions
  • 14.16. Mixed-Up Code Questions
  • 14.17. Write Code Questions
  • 15.1.1. Properly Formatted XML
  • 15.2.1. Using get to get the value of an attribute
  • 15.2.2. Getting Data from the First Element of a Type in XML
  • 15.2.3. Fixing Errors in XML
  • 15.2.4. Write Code to Process XML
  • 15.3. Looping through nodes
  • 15.4.1. List of Dictionaries
  • 15.5.1. Converting a JSON String into a Python Object
  • 15.5.2. Converting a Python object into a JSON string
  • 15.6.1. Getting JSON Data From an API
  • 15.6.2. Using a Dictionary for URL Parameters
  • 15.7. Security and API usage
  • 15.8. Glossary
  • 15.9. Multiple Choice Questions
  • 15.10. Mixed-Up Code Questions
  • 15.11. Write Code Questions
  • 15.12. Application 1: Google geocoding web service
  • 15.13. Application 2: Twitter
  • 16.1. Managing larger programs
  • 16.2. Getting started
  • 16.3. Using objects
  • 16.4. Starting with programs
  • 16.5. Subdividing a problem
  • 16.6. Our first Python object
  • 16.7. Classes as types
  • 16.8. Object lifecycle
  • 16.9. Multiple instances
  • 16.10. Inheritance
  • 16.11. Summary
  • 16.12. Glossary
  • 16.13. Multiple Choice Questions
  • 16.14. Mixed-Up Code Exercises
  • 16.15. Write Code Exercises
  • 16.16.1. A Book Class
  • 16.16.2. Create More Book Objects
  • 16.16.3. Add a Method to a Class
  • 16.17.1. Inheritance
  • 16.17.2. Overriding an Inherited Method
  • 17.1.1. What does a left turn of 90 mean?
  • 17.2. Practice with Turtles
  • 17.3. Turtle Methods
  • 17.4. Single and Multiple Turtles
  • 17.5. Using Repetition with Turtles
  • 17.6. Teacher Note: Turtle Geometry
  • 17.7. Total Turtle Trip Theorem
  • 17.8. Making Patterns within Patterns
  • 17.9. The Turtle Stamp Procedure
  • 17.10. Creating Functions with Turtles
  • 17.11.1. Summary of Turtle Methods
  • 17.11.2. Summary of Screen Methods
  • 17.12. Multiple Choice Questions
  • 17.13. Mixed-Up Code Questions
  • 17.14. Write Code Questions
  • 18.1. Using Repetition with Images
  • 18.2. Understanding Image Representation
  • 18.3. A Pattern for Image Processing
  • 18.4. Changing Step 5: Increasing and decreasing color values
  • 18.5. Changing Step 6: Changing where we put the colors
  • 18.6. Changing Step 3: Changing which data we use
  • 18.7. Image Chaper Summary
  • 18.8. Multiple Choice Questions
  • 18.9. Mixed-Up Code Exercises
  • 18.10. Write Code Exercises
  • 19.1. Object-oriented programming
  • 19.2. A change of perspective
  • 19.3. Objects Revisited
  • 19.4. User Defined Classes
  • 19.5. Improving our Constructor
  • 19.6. Adding Other Methods to our Class
  • 19.7. Objects as Arguments and Parameters
  • 19.8. Converting an Object to a String
  • 19.9. Instances as Return Values
  • 19.10.1. Multiple Classes
  • 19.10.2. Object-Oriented Analysis and Design
  • 19.10.3. UML Diagrams
  • 19.11. Multiple Classes Practice
  • 19.12. Multiple Choice Questions for Multiple Classes
  • 19.13. Glossary
  • 19.14. Multiple Choice Questions
  • 19.15. Mixed-Up Code Exercises
  • 19.16. Exercises
  • 20.1. Pillars of OOP
  • 20.2. Introduction to Inheritance - Point and LabeledPoint
  • 20.3. Call a Parent Method
  • 20.4. Reuse Through Association
  • 20.5. Class Diagrams
  • 20.6. Association vs. Inheritance
  • 20.7.1. Storing Postal Addresses
  • 20.7.2. Storing International Addresses
  • 20.7.3. Inheritance Applied
  • 20.7.4. A List of Addresses
  • 20.7.5. Using isinstance
  • 20.8.1. Testing your Code
  • 20.8.2. Creating Test Cases
  • 20.8.3. Understanding Unit Tests
  • 20.8.4. Writing Unit Tests
  • 20.9.1. Assert methods
  • 20.9.2. Writing Unit Tests
  • 20.10. Multiple Choice Questions
  • 20.11. Mixed-Up Code Questions
  • 20.12. Write Code Questions
  • 21.1. What is a database?
  • 21.2. Database concepts
  • 21.3. Database Browser for SQLite
  • 21.4. Creating a database table
  • 21.5. Structured Query Language summary
  • 21.6. More SELECT Keywords
  • 21.7. Spidering Twitter using a database
  • 21.8. Basic data modeling
  • 21.9.1. Constraints in database tables
  • 21.9.2. Retrieve and/or insert a record
  • 21.9.3. Storing the friend relationship
  • 21.10. Three kinds of keys
  • 21.11. Using JOIN to retrieve data
  • 21.12. Summary
  • 21.13. Debugging
  • 21.14. Glossary
  • 21.15. Multiple Choice Questions
  • 21.16. Mixed-Up Code Questions
  • 21.17. Write Code Questions
  • 22.1. Visualizing data
  • 22.2. Building a Google map from geocoded data
  • 22.3. Visualizing networks and interconnections
  • 22.4. Visualizing mail data
  • 22.5. Multiple Choice Questions
  • 22.6. Mixed-Up Code Questions

Acknowledgements ¶

Acknowledgements, Contributors, License, and Preface

  • Contributions
  • Copyright Detail for Python for Everybody
  • Credits for Python for Everybody
  • Printing History for for Python for Everybody
  • Copyright Details for for Python for Everybody
  • Remixing an Open Book

Search Page

CSVidyalay

Programming for Everybody (Getting Started with Python) Answers

  • Post category: Coursera Solutions
  • Post comments: 1 Comment

Stuck on your journey to learn Python? Get your questions answered in our “Programming for Everybody (Getting Started with Python) Answers” post! We tackle common roadblocks for beginners, making coding accessible for everyone.

What you will learn in the course “Programming for Everybody (Getting Started with Python) “ ?

  • Install Python and write your first program
  • Describe the basics of the Python programming language
  • Use variables to store, retrieve, and calculate information
  • Utilize core programming tools such as functions and loops

Programming for Everybody (Getting Started with Python) Answers

  • 1.1 Week 3 Programming for Everybody – Assignment:
  • 1.2 Week 3 Programming for Everybody – Quiz:
  • 2.1 Week 4 Assignment 2.2:
  • 2.2 Week 4 Assignment 2.3:
  • 2.3 Week 4 Programming for Everybody – Quiz:
  • 3.1 Week 5 Assignment 3.1:
  • 3.2 Week 5 Assignment 3.3:
  • 3.3 Week 5 Programming for Everybody – Quiz:
  • 4.1 Week 6 Programming for Everybody – Assignment 4.6:
  • 4.2 Week 6 Programming for Everybody – Quiz:
  • 5.1 Week 7 Programming for Everybody – Assignment 5.2:
  • 5.2 Week 7 Programming for Everybody – Quiz:

Week 3 – Programming for Everybody (Getting Started with Python)

Week 3 programming for everybody – assignment:.

Write a program that uses a print statement to say ‘hello world’ as shown in ‘Desired Output’.

Week 3 Programming for Everybody – Quiz:

1. When Python is running in the interactive mode and displaying the chevron prompt (>>>) – what question is Python asking you?

Answer – What would you like to do?

2. What will the following program print out: >>> x = 15; >>> x = x + 5; >>> print x

Answer – 20

3. Python scripts (files) have names that end with:

Answer – .py

4. Which of these words are reserved words in Python?

Answer – if break

5. What is the proper way to say “good-bye” to Python?

Answer – quit()

6. Which of the parts of a computer actually executes the program instructions?

Answer – Central Processing Unit

7. What is “code” in the context of this course?

Answer – A sequence of instructions in a programming language

8. A USB memory stick is an example of which of the following components of computer architecture?

Answer – Secondary Memory

9. What is the best way to think about a “Syntax Error” while programming?

Answer – The computer did not understand the statement that you entered

10. Which of the following is not one of the programming patterns covered in Chapter 1?

Answer – Random steps

Week 4 – Programming for Everybody (Getting Started with Python)

Week 4 assignment 2.2:.

Write a program that uses input to prompt a user for their name and then welcomes them. Note that input will pop up a dialog box. Enter Sarah in the pop-up box when you are prompted so your output will match the desired output.

Week 4 Assignment 2.3:

Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking or bad user data.

Week 4 Programming for Everybody – Quiz:

1. In the following code, print 98.6. What is “98.6”?

Answer – A constant

2. In the following code, x = 42. What is “x”?

Answer – A variable

3. Which of the following variables is the “most mnemonic”?

Answer – hours

4. Which of the following is not a Python reserved word?

Answer – speed

5. Assume the variable x has been initialized to an integer value (e.g., x = 3). What does the following statement do? x = x + 2.

Answer – Retrieve the current value for x, add two to it and put the sum back into x

6. Which of the following elements of a mathematical expression in Python is evaluated first?

Answer – Parenthesis()

7. What is the value of the following expression

Answer – 2

8. What will be the value of x after the following statement executes: x = 1 + 2 * 3 – 8 / 4

Answer – 5

9. What will be the value of x when the following statement is executed: x = int(98.6)

Answer – 98

10. What does the Python raw_input() function do?

Answer – Pause the program and read data from the user

Week 5 – Programming for Everybody (Getting Started with Python)

Week 5 assignment 3.1:.

3.1 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number.

Do not worry about error checking the user input – assume the user types numbers properly.

Week 5 Assignment 3.3:

Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table: Score Grade

= 0.9 A = 0.8 B = 0.7 C = 0.6 D < 0.6 F If the user enters a value out of range, print a suitable error message and exit. For the test, enter a score of 0.85.

Week 5 Programming for Everybody – Quiz:

1. What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement is true?

Answer – Indent the line below the if statement

2. Which of these operators is not a comparison / logical operator?

Answer – =

3. What is true about the following code segment: if x == 5 : print ‘Is 5’ print ‘Is Still 5’ print ‘Third 5’

Answer – Depending on the value of x, either all three of the print statements will execute or none of the statements will execute

4. When you have multiple lines in an if block, how do you indicate the end of the if block?

Answer – You de-indent the next line past the if block to the same level of indent as the original if statement

5. You look at the following text: if x == 6 : print ‘Is 6’ print ‘Is Still 6’ print ‘Third 6’. It looks perfect but Python is giving you an ‘Indentation Error’ on the second print statement. What is the most likely reason?

Answer – You have mixed tabs and spaces in the file

6. What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is false?

Answer – else

7. What will the following code print out? x = 0 if x < 2 : print ‘Small’ elif x < 10 : print ‘Medium’ else : print ‘LARGE’ print ‘All done’

Answer – Small All done

8. For the following code, if x < 2: print ‘Below 2’ elif x >= 2: print ‘Two or more’ else: print ‘Something else’. What value of ‘x’ will cause ‘Something else’ to print out?

Answer – This code will never print ‘Something else’ regardless of the value for ‘x’

9. In the following code (numbers added) – which will be the last line to execute successfully? (1) astr = ‘Hello Bob’; (2) istr = int(astr); (3) print ‘First’, istr; (4) astr = ‘123’; (5) istr = int(astr); (6) print ‘Second’, istr

Answer – 1

10. For the following code: astr = ‘Hello Bob’ istr = 0 try: istr = int(astr) except: istr = -1. What will the value be for istr after this code executes?

Week 6 – Programming for Everybody (Getting Started with Python)

Week 6 programming for everybody – assignment 4.6:.

Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours.

Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input unless you want to – you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.

Week 6 Programming for Everybody – Quiz:

1. Which Python keyword indicates the start of a function definition?

Answer – def

2. In Python, how do you indicate the end of the block of code that makes up the function?

Answer – You de-indent a line of code to the same indent level as the def keyword

3. In Python what is the raw_input() feature best described as?

Answer – A built-in function

4. What does the following code print out? def thing(): print ‘Hello’; print ‘There’

Answer – There

5. In the following Python code, which of the following is an “argument” to a function? x = ‘banana’; y = max(x); print y

Answer – x

6. What will the following Python code print out? def func(x) : print x; func(10); func(20)

Answer – 10, 20

7. Which line of the following Python program is useless? def stuff(): print ‘Hello’ return print ‘World’ stuff()

Answer – print ‘World’

8. What will the following Python program print out? def greet(lang): if lang == ‘es’: return ‘Hola’ elif lang == ‘fr’: return ‘Bonjour’ else: return ‘Hello’ print greet(‘fr’),’Michael’

Answer – Bonjour Michael

9. What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug – so read carefully). def addtwo(a, b): added = a + b return a; x = addtwo(2, 7); print x

10. What is the most important benefit of writing your own functions?

Answer – Avoiding writing the same non-trivial code more than once in your program

Week 7 – Programming for Everybody (Getting Started with Python)

Week 7 programming for everybody – 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. 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. Enter 7, 2, bob, 10, and 4 and match the output below.

Week 7 Programming for Everybody – Quiz:

1. What is wrong with this Python loop: n = 5; while n > 0 : print n; print ‘All done’

Answer – This loop will run forever.

2. What does the break statement do?

Answer – Exits the currently executing loop.

3. What does the continue statement do?

Answer – Jumps to the “top” of the loop and starts the next iteration.

4. What does the following Python program print out? tot = 0; for i in [5, 4, 3, 2, 1] : tot = tot + 1; print tot

5. What is the iteration variable in the following Python code: friends = [‘Joseph’, ‘Glenn’, ‘Sally’]; for friend in friends : print ‘Happy New Year:’, friend; print ‘Done!’

Answer – friend

6. What is a good description of the following bit of Python code?; zork = 0; for thing in [9, 41, 12, 3, 74, 15] : zork = zork + thing; print ‘After’, zork

Answer – Sum all the elements of a list

7. What will the following code print out? smallest_so_far = -1; for the_num in [9, 41, 12, 3, 74, 15] : if the_num < smallest_so_far : smallest_so_far = the_num; print smallest_so_far

8. What is a good statement to describe the is operator as used in the following if statement: if smallest is None : smallest = value

Answer – matches both type and value

9. Which reserved word indicates the start of an “indefinite” loop in Python?

Answer – while

10. How many times will the body of the following loop be executed? n = 0; while n > 0 : print ‘Lather’ print ‘Rinse’; print ‘Dry off!’

Answer – 0

Must Read: Google and the Department of Defense Build AI-Powered Microscope to Aid Cancer Detection

You Might Also Like

Read more about the article Coursera Introduction to Data Analytics Quiz Solutions

Coursera Introduction to Data Analytics Quiz Solutions

Read more about the article Coursera Introduction to Programming with MATLAB Answers

Coursera Introduction to Programming with MATLAB Answers

Read more about the article Coursera Crash Course on Python Solutions

Coursera Crash Course on Python Solutions

guest

Thank you! I received my certificate.

IMAGES

  1. Coursera Assignment 2.3 Solved Python for Everybody

    python for everybody coursera assignment 2.3

  2. Coursera : python for everybody assignment 2.3 solution (getting

    python for everybody coursera assignment 2.3

  3. Coursera: Programming For Everybody Assignment 2.3 program solution Answer |Python for Everybody 2.3

    python for everybody coursera assignment 2.3

  4. Coursera Assignment 2.3 python for everybody

    python for everybody coursera assignment 2.3

  5. Coursera Python for Everybody EP-6

    python for everybody coursera assignment 2.3

  6. Assignment 2.3

    python for everybody coursera assignment 2.3

VIDEO

  1. Assignment

  2. 1 3 Python as a Language University of Michigan Coursera

  3. Coursera: Week 3: Assignment Hello World

  4. Assignment 9.4 Python Data Structures

  5. Python Data Structure Coursera complete Assignment Solution Python for Everybody 100% Solution #DCG

  6. "Python for Everybody" Chapter 12

COMMENTS

  1. python-for-everybody/wk2

    wk2 - assignment 2.3.py. Cannot retrieve latest commit at this time. # 2.3 Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay. # Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). # You should use raw_input to read a string and float () to convert the string ...

  2. Assignment 2.3

    CourseraProgramming for Everybody (Getting Started with Python)Week 4 Assignment 2.3 Question: 2.3 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). You should…

  3. Python-for-Everybody-Coursera/week4-assignment 2.3 at main

    Here is the solution of the problems in the weekly basis. - Python-for-Everybody-Coursera/week4-assignment 2.3 at main · adibaruet/Python-for-Everybody-Coursera

  4. Coursera-Python-for-everybody-Solution/Assignment 2.3 at master

    Answer to all the assignments of the Coursera course - Zeus272000/Coursera-Python-for-everybody-Solution

  5. Coursera Python for Everybody EP-6

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

  6. Coursera : python for everybody assignment 2.3 solution (getting

    Program :hrs = input("Enter Hours")rat = input("Enter Rates")pay = float(hrs) * float(rat)print('Pay: ', pay).....

  7. Coursera: Assignment 2.3 Python For Everybody

    Coursera: Programming For Everybody Assignment 2.3 program solution Answer | Python for Everybody Assignment 2.3 program solution.Hello friends, In this vide...

  8. Exercise 2.3

    Exercise 2.3 - Python for Everybody This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters. Show hidden characters ...

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

  10. Coursera---Programming-for-Everybody-Getting-Started-with-Python-/Week

    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. - Coursera---Programming-for-Everybody-Getting-Started-with-Python-/Week 4 - Assignment 2.3 at master · Ritik2703/Coursera---Programming-for-Everybody-Getting-Started-with-Python-

  11. Python for Everyone

    At Quizlet, we're giving you the tools you need to take on any subject without having to carry around solutions manuals or printing out PDFs! Now, with expert-verified solutions from Python for Everyone 2nd Edition, you'll learn how to solve your toughest homework problems. Our resource for Python for Everyone includes answers to chapter ...

  12. Coursera Assignment 2.3 Solved Python for Everybody

    Coursera Programming for Everybody Assignment 2.3 Solution | Python For Everybody assignment 2.3 Solthis is coursera assignment assignment 2.3 completely solved

  13. Python for Everybody

    Python for Everybody - Interactive¶ Assignments¶ Assignments; Table of Contents ...

  14. Python for Everybody Specialization [5 courses] (UMich)

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

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

  16. Coursera:chapter 2.3 python for everybody Assignment solution

    # Coursera :- #Programing for everybody # PythonCHAPTER :- QUIZ QUESTION WITH ANSWER👇Chapter :- 1 Quiz 👇https://youtu.be/fVsdDMrP6IA👇Chapter :- 2 Qui...

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

  18. Programming for Everybody (Getting Started with Python) Answers

    Get your questions answered in our "Programming for Everybody (Getting Started with Python) Answers" post! We tackle. ... Week 6 Programming for Everybody - Assignment 4.6: ... Next Post Wireless Communications for Everybody Coursera Answers. You Might Also Like. Coursera IBM What is Data Science Quiz Answers April 16, 2024 ...

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

  20. Assignment 3.1

    CourseraProgramming for Everybody (Getting Started with Python)Week 5 Assignment 3.1 Question: 3.1 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40…

  21. Coursera: Programming For Everybody Assignment 2.3 program solution

    Coursera: Programming For Everybody Assignment 2.3 program solution Answer | Python for Everybody Assignment 2.3 program solution👇Solution Pdf download👇( c...

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