CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2022
    Posts
    44

    I am getting error in python programming question(PLs have a look)

    Below is question, solution, and error i get when i run solution of this question below.

    Q-

    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.

    SOlution-

    largest=none
    smallest=none
    while true:
    inp=input("enter number")
    if inp=="done": break
    try:
    num=float(inp)
    except:
    print("Invalid Input")
    continue
    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("minimun is",int(smallest))
    done(largest,smallest)



    error-

    ERROR: C:\Users\Wali\Desktop\Py4e>ex5.2.py
    File "C:\Users\Wali\Desktop\Py4e\ex5.2.py", line 3
    while true:
    IndentationError: unexpected indent

  2. #2
    Join Date
    Nov 2018
    Posts
    118

    Re: I am getting error in python programming question(PLs have a look)

    Quote Originally Posted by existenceproduct View Post
    Below is question, solution, and error i get when i run solution of this question below.

    Q-

    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.

    SOlution-

    largest=none
    smallest=none
    while true:
    inp=input("enter number")
    if inp=="done": break
    try:
    num=float(inp)
    except:
    print("Invalid Input")
    continue
    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("minimun is",int(smallest))
    done(largest,smallest)



    error-

    ERROR: C:\Users\Wali\Desktop\Py4e>ex5.2.py
    File "C:\Users\Wali\Desktop\Py4e\ex5.2.py", line 3
    while true:
    IndentationError: unexpected indent
    Repost bot - original is here.
    https://www.reddit.com/r/learnpython...n_programming/
    Last edited by 2kaud; February 4th, 2023 at 05:21 AM.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: I am getting error in python programming question(PLs have a look)

    @existenceproduct - why repost a question from 3 years ago that has already been answered??
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured