Python Forum
Coursera python for everybody 5.2 assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coursera python for everybody 5.2 assignment
#1
I'm stuck with this. This is the requirement 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.

My code:

largest = None
smallest = None
while True:
    num = float(input("Enter a number: "))
    for i in num:
     if i > largest:
     largest = i
    print(largest)
    break
    for i in num:
    if num <smallest
    smallest=num
    print(num)
    except
    print("Invalid input)
    if num == "done" : break
    print(num)

print("Maximum is", largest, "Minimum is", smallest)
Reply
#2
I guess the python interpreter is not very happy with your code. The important part is the error message sent by python. By reading it carefuly you can find where there is an error in the code. You can post the error message here between error tags.
Reply
#3
The error is bad input on line 7
Reply
#4
Well my python interpreter is more talkative. How do you run the code?
Error:
File "paillasse/tmp/badinput.py", line 7 largest = i ^ IndentationError: expected an indented block
It tells me that line 7 has a bad indentation. You need to add more space at the beginning of the line. It must not be aligned with the 'if' of the previous line.
Reply
#5
I was using that py4e.com playgound. Does visual studio do it?
Reply
#6
In python programming, it is very important to have the whole error message at execution. In principle, all IDEs print the error traceback. If you execute python code in a terminal, you also have the error traceback. This error message is a major feature of Python because it makes program very easy to debug.
Reply
#7
(Sep-02-2020, 11:35 AM)SteppentigerV2 Wrote: I was using that py4e.com playgound
Dos in not print the whole Traceback?
I guess is dos,if it do not then is useless.
(Sep-02-2020, 11:35 AM)SteppentigerV2 Wrote: Does visual studio do it?
All editor should give show that Traceback output,and very few in the Python world use Visual Studio.
A lot use VS Code which is not the same as Visual Studio.
Is VS Code if a Linter if turned on give a Warning before running the code.
Here a example how this look,the linter i use here is Pylint.
[Image: uvSEZ5.png]
Reply
#8
I wrote a code which gives valid output,
but still I get message "you should actually compute the maximum and minimum".
What do they want from me? :)

l = 0
s = 1000000
while True:
num = input("Enter a number: ")
if num == "done": break
try: n = int(num)
except: print('Invalid input')
if n > l: l = n
if n < s: s = n
continue

print("Maximum is", l)
print("Minimum is", s)
Reply
#9
Please use the Python tags when posting code.

Without knowing the assignment, tough to know what they are asking. This works for integers, not floats, and only in a particular range. A set of negative numbers will give the wrong answer.

What was the assignment?
Reply
#10
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python for Everybody 5.2 assignment baba04201 20 173,379 Jul-25-2023, 04:15 PM
Last Post: MicaelSchutz
  Python for Everybody 3.1 assignment ramadan2099 18 45,425 Jan-23-2021, 06:27 AM
Last Post: KonohaHokage
  [split] Python for Everybody 5.2 assignment ramadan2099 3 12,062 Jul-15-2020, 04:54 PM
Last Post: Bipasha
  Python Assignment 3 - Applied Data Science - 2.3 eyavuz21 8 4,973 Jun-06-2020, 08:59 AM
Last Post: eyavuz21
  Python Password Saver Assignment sshellzr21 2 6,174 May-02-2020, 01:34 AM
Last Post: sshellzr21
  Python for Everybody 3.3 assignment ramadan2099 7 31,748 Apr-08-2020, 06:49 AM
Last Post: DeaD_EyE
  Python for everyone course assignment 5.2 ofekx 3 8,543 Dec-23-2019, 08:41 PM
Last Post: nilamo
  [split] Python for Everybody 5.2 assignment jonchanzw 4 8,474 Oct-22-2019, 08:08 AM
Last Post: perfringo
  Python Assignment 5.2 amos76823 3 15,976 Jan-17-2019, 07:34 AM
Last Post: perfringo
  Spyder Assignment 1 Coursera Illvoices 2 3,200 Feb-08-2018, 05:18 AM
Last Post: Illvoices

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020