python for everybody | Coursera Community
Coursera Header
Question

python for everybody

  • 30 April 2020
  • 38 replies
  • 59862 views

Userlevel 1
Badge +1

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.

 

largest = None
smallest = None
while True:
    num = input("Enter a number: ")
    if num == "done": break
    try:
        num = int(num)
        if largest is None or largest < num: largest = num
        if smallest is None or smallest > num: smallest = num
    except:
        print ("Invalid input")
        continue
print ("Maximum is",largest)
print ("Minimum is",smallest)

can anyone help with  me solution regarding this.


38 replies

Badge +1

This code produces correct output. What is wrong with it?

Badge +1

What help do you want? Please specify.

Badge

 

Badge

 

what input i write 

Badge +1
Code Is absolutely Right.

 

Badge

I`m unable to exit the popup box in google browser while entering input….someone please help...

Badge

 

WHEN I COMPLETE THE PROGRAM WHEN I CLICK ON CHECK CODE THEN OPTION IS COMING ENTER  A NUMBER 

WHAT NUMBER SHOULD I WRITTEN

 

Badge

Please anybody will send input of this program

 

Badge

l = None
s = None
while True:
    try:
        num = input("Enter a number: ")
        if num == "done" :
            break
    except:
        print('invalid input')
        continue    
    if s is None or s > num:
        s = num
    if l is None or l < num:
        l = num

print("Maximum is", l)
print("Minimum is", s)

 

What's wrong with this code>?? Please help

Badge

 

after entering correct input it will again and again  asking enter the number . can you please help me?

Badge

Im unable to get the output for this program. Once the number is entered ,its a continous loop .so no output 

Badge

Can u plz help me out

Badge

And the program my subodh kr , its always showing an error regarding try

Badge

This is the continuous loop that im getting

Userlevel 2
Badge +2

Kindly reach me via whatsapp for more information on that. My whatsapp number is +918200713617

Badge

I have my code correct. When i try it with online compiler I get the same desired output. But when I  enter the input,  I get the same check box again and again. I tirec of trying.

Someone pls help me.

Badge

Many of u have replied the same problem…. then how did u guys did it?

Badge +2

This is the continuous loop that I'm getting

It'll generally request the input. Since the loop is developed in that manner until 'done' is entered.

Badge +2

I have my code correct. When i try it with online compiler I get the same desired output. But when I  enter the input,  I get the same check box again and again. I tirec of trying.

Someone pls help me.

Mentor in the discussion forums can help you better. In some cases, we need to compose code in just the way as it instructs in the course. I also had got huge amounts of errors, however later I understood that we should adhere to course step-per-step guidelines. (Because sometimes I used the logic which was taught later in the course)

Another way is you can reopen the assignment, and attempt it once more. In the event, if you can attach screenshots, I can help you better. Happy learning :)

Badge

 

after entering correct input it will again and again  asking enter the number . can you please help me?

hello ,you will have to give the following inputs in order to get the code executed without any mismatch

1)bob

2)7

3)2

4)10

5)4

6)done

 

Badge +1

 

 

after entering correct input it will again and again  asking enter the number . can you please help me?

hello ,you will have to give the following inputs in order to get the code executed without any mismatch

1)bob

2)7

3)2

4)10

5)4

6)done

 

 

Badge +1

this code is not working on line 9

Userlevel 2
Badge +2

Exactly sonam…

the code will not work… and should not work.

 

It is the misuse of except block. and in the try block there will never be any error… so except block will never get a chance to execute.

 

for more information, please reach me via whatsapp at +918200713617

Badge

 

#Input will be:

7

2

bob

10

4

Userlevel 2
Badge +2

this code is not working on line 9

How are you sonam?

 

After getting my help, everything should work fine… And I hope You got the certificate…

 

Congratulation. I am glad that I had you.

Reply