Geeks of Coding

Join us on Telegram

Home Forums Assignment courserra Python for Everybody – Specialization Programming for Everybody (Getting started with Python) Assignment 5.2, Programming for Everybody (Getting started with Python)

Viewing 0 reply threads
  • Author
    • #873
      Abhishek TyagiAbhishek Tyagi

      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:
          inp = input("Enter a number: ")
          if inp == "done" : break
              num = float(inp)
              print("Invalid input")
          if smallest is None:
              smallest = num 
          if num > largest :
              largest = num
          elif num < smallest :
              smallest = num
      def done(largest,smallest):
          print("Maximum is", int(largest))
          print("Minimum is", int(smallest))
Viewing 0 reply threads
  • You must be logged in to reply to this topic.