-1

Code is here. https://gist.github.com/anonymous/3dfa30bf0c9470200e5bcebce723836e

Can't figure this out for the life of me. All I need is a simple if/elif statement to ask the user if they want to send an email or check their contacts.

  • Did you read the error and look at the respective code...? How can you let an if/elif span a try/except? It all has to be in the same enclosing block... – Andrew Li Jan 18 '17 at 12:44
  • Please post the relevant code. – Shivkumar kondi Jan 18 '17 at 12:45
  • Possible duplicate of [IndentationError: unindent does not match any outer indentation level](http://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) –  Jan 18 '17 at 12:48
  • please don't link to code on another site. Post the _relevant_ bits of code directly in the question and apply proper formatting to it. – Bryan Oakley Jan 18 '17 at 12:58

2 Answers2

0

Put your else part after if condition and try to use 1-tab indentation in your code

import random
import time
import sys
import smtplib

while x==0:
    try:
        ask=str(input("What would you like to do? Send an email, check your contact book, or edit your calendar? "))
        if "email" or "mail" or "send" in ask:
            print ("Please log in to your email ")
            user=str(input("Email "))
            pwd=str(input("Password "))
            content=str(input("Enter your message "))
            sndr=user #this is to prevent email spoofing or fraud
            rcpt=str(input("Enter a recipient "))





            mail = smtplib.SMTP('smtp.gmail.com',587) #or port 465

            mail.ehlo()

            mail.starttls()

            mail.login(user,pwd)

            mail.sendmail(sndr, rcpt, content)

            mail.close()
        elif "check" or "contact" or "book" in ask:
                print ("working")
    except smtplib.SMTPAuthenticationError:
            print ("Login Failed. Please try again")
Shivkumar kondi
  • 6,458
  • 9
  • 31
  • 58
0

In your code the structure is as follows:

try:
    if:
except:
    elif:

This cannot work, because the elif does not have an associated if. Imagine if an if could span the except: if an exception occurred before your if, the elif does not have an associated if, which breaks logic.

Jesse Bakker
  • 2,403
  • 13
  • 25