Python for Everybody

Exercise 4.1, exercise 4.2, exercise 4.6, exercise 4.7.

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

Python for everybody assignment 3.3

Why wouldn't my for loop work? If I put in 0.85 for grade score it'd print out F and error message instead of B. Why is this?

John Kugelman's user avatar

  • What makes you think you need a loop? You should try without it. –  quamrana Commented May 25, 2022 at 20:55
  • agred, the range(0, 1) is probably redundant –  Wizard.Ritvik Commented May 25, 2022 at 20:56
  • 3 It's not clear what for fg in range(0,1): is supposed to do; you're completely overwriting and replacing fg with the integer value 0 . It seems that you don't know or understand what range() does. –  Random Davis Commented May 25, 2022 at 20:57
  • Add some prints, do some debug. Your loop runs once and sets fg to 0 so the else always runs –  Tomerikoo Commented May 25, 2022 at 20:57
  • 3 @rv.kvetch what's the point of looping at all? It seems like only the if statement is needed –  Random Davis Commented May 25, 2022 at 20:57

3 Answers 3

You are misusing the range() function. range() is used to iterate over multiple values, not to validate if a number is in a range. You should instead check that fg greater than or equal to 0, or less than or equal to 1. Like this:

Michael M.'s user avatar

  • 1 or maybe: if not 0 <= fg <= 1: –  Wizard.Ritvik Commented May 25, 2022 at 21:02
  • " range() is used to iterate over multiple values, not to validate if a number is in a range" - depends what type of range. It wouldn't work in this case with floats, but you can totally do if value in range(2, 6) to check for natural numbers –  Tomerikoo Commented May 25, 2022 at 21:05

you are doing this for one time you dont need to use a loop you can do this

Afshar Sharifi's user avatar

You do not need to use for operator neither range. The simplest solution is:

grade = input("Enter number:") try: grade = float(grade) except: grade = -1

blast's user avatar

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 or ask your own question .

  • The Overflow Blog
  • The world’s largest open-source business has plans for enhancing LLMs
  • Featured on Meta
  • User activation: Learnings and opportunities
  • Site maintenance - Mon, Sept 16 2024, 21:00 UTC to Tue, Sept 17 2024, 2:00...
  • What does a new user need in a homepage experience on Stack Overflow?
  • Announcing the new Staging Ground Reviewer Stats Widget

Hot Network Questions

  • What does "either" refer to?
  • Does the different strength of gravity at varying heights affect the forces within a suspended or standing object
  • Modifying Expansion Order with \seq put right
  • \luastring variant that expands tokens once if they are a cs
  • What is an apologetic to confront Schellenberg's non-resistant divine hiddenness argument?
  • Determining Entropy in PHP
  • Why did the Chinese government call its actual languages 'dialects'? Is this to prevent any subnational separatism?
  • Inverses of Morphisms Necessarily Being Morphisms
  • I am an imaginary variance
  • マリネする vs. マリネにする "to marinate"
  • How to fix: "Error dependency is not satisfiable"?
  • How do I remove a wheel axle with smooth circular bolts?
  • Why is the center of a meniscus completely flat?
  • Would a scientific theory of everything be falsifiable?
  • Fifth year PhD student with no progress on my thesis because of advisor, what to do?
  • Is it possible to invert the f-curve?
  • Python script to renumber slide ids inside a pptx presentation
  • Is it possible/recommended to paint the side of piano's keys?
  • how does the US justice system combat rights violations that happen when bad practices are given a new name to avoid old rulings?
  • Convert base-10 to base-0.1
  • How Can I Modify a C Program to Gain Root Shell Access Without Using Sudo or Editing the Sudoers File?
  • Seeking a Text-Based Version of Paul Dirac's 1926 Paper on Quantum Mechanics
  • Driving low power LEDs from pre-biased digital transistors
  • If someone threatens force to prevent another person from leaving, are they holding them hostage?

assignment 4 6 python for everybody github

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

IMAGES

  1. 4.6 python for everyone · Issue #3 · Lallo/PR4E · GitHub

    assignment 4 6 python for everybody github

  2. 4.6 python for everyone · Issue #3 · Lallo/PR4E · GitHub

    assignment 4 6 python for everybody github

  3. GitHub

    assignment 4 6 python for everybody github

  4. Programming for Everybody (Getting Started with Python) ||Week 6 || Assignment 4.6 Coursera

    assignment 4 6 python for everybody github

  5. 【Python for Everybody(Getting Started with Python)】Week 6

    assignment 4 6 python for everybody github

  6. Coursera: Python For Everybody Assignment 4.6 program solution

    assignment 4 6 python for everybody github

VIDEO

  1. Python For Everybody Honors Recognition Assignment 2

  2. EN ZOR KONUYU ÇÖZDÜK!

  3. "Python for Everybody" Chapter 3

  4. Coursera: 8.4 Assignment// python data structures assignment 8.4 solution

  5. Grand Assignment

  6. Programming for Everybody Getting Started with Python Coursera complete Assignment Solution #DCG

COMMENTS

  1. python-for-everybody/wk4

    wk4 - assignment 4.6.py. Cannot retrieve latest commit at this time. History. Code. Blame. 17 lines (13 loc) · 897 Bytes. 4.6 Write a program to prompt the user for hours and rate per hour using raw_input to compute gross pay. Award time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of ...

  2. python-for-everybody-assignments/Assignment_4.6.py at main

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

  3. Python for everybody

    The second pay should be beneath se of the else: and lastly return pay should be in alignment with else: so it should be if hours, else: and return pay aligned correctly and the same for pay by using the space bar in your pc. There two spaces after lines:6 and 10. Python for everybody - Assignment 4.6. GitHub Gist: instantly share code, notes ...

  4. Python For everybody Assignment 4.6 · GitHub

    Python For everybody Assignment 4.6. GitHub Gist: instantly share code, notes, and snippets. ... Python For everybody Assignment 4.6 Raw. Assignment 4.6. Py 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 ...

  5. Assignment 4.6

    CourseraProgramming for Everybody (Getting Started with Python)Week 6 Assignment 4.6 Question: 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…

  6. Python-for-Everybody/Programming for Everybody/Chapter 4/Assignment 4.6

    Contribute to zatang007/Python-for-Everybody development by creating an account on GitHub. ... Assignment 4.6.py. Blame. Blame. Latest commit ...

  7. Coursera Python for everybody Assignments 4.6 and 5.2

    This is the first part of videos of solutions for python for everybody courses on Coursera, for more information go to my git-hub pagehttps://github.com/Akhi...

  8. Projects

    Exercise 4.6. """ Exercise 4.6: Rewrite your pay computation with time-and-a-half for overtime and create a function called computepay which takes two paramteters (hours and rate). Enter Hours: 45 Enter Rate: 10 Pay: 475.0 Python for Everybody: Exploring Data Using Python 3 by Charles R. Severance Solution by Jamison Lahman, May 28, 2017 ...

  9. Python for everybody

    Python for everybody - Assignment 4.6. GitHub Gist: instantly share code, notes, and snippets. ... Python for everybody - Assignment 4.6 Raw. gistfile1.txt 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 ...

  10. Python For Everybody Specialization, Programming for ...

    Python For Everybody Specialization, Programming for Everybody (Getting Started with Python), Assignment 4.6: Compute Pay V4 - py4e-pfe-4_6-computePayV4.py

  11. Coursera Python for Everybody EP-11

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

  12. GitHub

    Assignment solutions and quiz answers for the 'Programming for Everybody (Getting Started with Python)' course by the University of Michigan on Coursera. Resources Readme

  13. Python for everybody assignment 3.3

    Python for everybody assignment 3.3. Ask Question Asked 2 years, 3 months ago. Modified 2 years, ... It wouldn't work in this case with floats, but you can totally do if value in range(2, 6) to check for natural numbers - Tomerikoo. Commented May 25, 2022 at 21:05. Add a comment | ... Need tips in Global Variables Assignment in Python for ...

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

  15. Python For Everybody Assignment 3.3 program solution

    Coursera: Python For Everybody Assignment 3.3 program solution | Assignment 3.3 Python For EverybodyCode link: https://drive.google.com/file/d/1hIpwhM8wLrLZi...

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

  17. assignment 4.6 python for everybody

    assignment 4.6 python for everybody coursera python for everybody assignment 4.6 python for everybody chapter 4 assignment python for everybody coursera assignment 4.6 python for everybody coursera assignment 4.6 python 3. Code examples. 178055. Follow us on our social networks. IQCode. About us Press Blog.

  18. Exercise 5.2

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

  19. GitHub

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

  20. Week 6- Assignment 4.6

    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 6- Assignment 4.6 at master · Ritik2703/Coursera---Programming-for-Everybody-Getting-Started-with-Python-

  21. python-for-everybody-assignments/Ch2

    Assignment solutions and quiz answers for the &#39;Programming for Everybody (Getting Started with Python)&#39; course by the University of Michigan on Coursera. - vaibhav-hariramani/python... Skip to content

  22. python-for-everybody-assignments/Assignment_2.3.py at main

    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.

  23. python-for-everybody-assignments/Assignment_2.2.py at main

    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.