#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    3
    Rep Power
    0

    mismatched input 'else' expecting EOF


    import time

    a = 8
    b = 3



    print("The width of a rectangle is 8cm and the height is 3cm.")
    calculate = input("Do you wish to calculate the area of this rectangle? ")
    if calculate == 'yes' or 'Yes' or 'y':
    print("Calculating.. please wait")
    time.sleep(3)
    print("The area of this rectangle is", a * b)

    else:
    calculate == 'no' or 'No' or 'n':
    print("Goodbye.")


    Can anyone help me please?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    471
    Rep Power
    71
    Code:
    if calculate == 'yes' or 'Yes' or 'y': 
        print("Calculating.. please wait")
    time.sleep(3)
    print("The area of this rectangle is", a * b)
    
    else:
        calculate == 'no' or 'No' or 'n':
            print("Goodbye.")
    There are two distinct problems. The one in which the Python interpreter stopped was the missing indentation of lines probably intended as part of the “then” block. That is, you should indent time.sleep() and print() calls.

    The next problem is the line “calculate == 'no' or 'No' or 'n':” which doesn’t parse as correct Python.

    I think you mean something like:

    Code:
    if calculate.lower() in ('y', 'yes'):
        # anything following “yes” here, *indented*
    elif calculate.lower() in ('n', 'no'):
        # anything following “no” here
    else:
        # the answer given is neither “yes” nor “no”

    Comments on this post

    • daleyb123 agrees
    My armada: Debian GNU/Linux 8 (desktop, home laptop, work laptop), Raspbian GNU/Linux 8 (nameserver), Ubuntu 14.04.3 LTS (HTPC), PC-BSD 10.2 (testbed), Android 4.2.1 (tablet)

IMN logo majestic logo threadwatch logo seochat tools logo