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

    Join Date
    Sep 2012
    Posts
    66
    Rep Power
    2

    Um why does this return a error


    so heres my code



    anything_else = " "

    Facebook = True

    Tumblr = True

    Youtube = False

    social_networks = input (" \n \n \t Name a social network ")

    social2 = eval (social_networks)

    if social2 == True:
    print ("yup")

    elif social2 != True:
    print ("no")


    else:
    print ("ERROR")


    except when I type random stuff into the input function
    it returns a error:


    Traceback (most recent call last):
    File "/Users/THEHATTER/Desktop/tits.py", line 11, in <module>
    social2 = eval (social_networks)
    File "<string>", line 1
    h]j
    ^
    SyntaxError: invalid syntax
    >>>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    25
    Rep Power
    0
    you have indent the if statement.
    Code:
    if social2 == True:
         print ("yup") 
    
    elif social2 != True:
        print ("no") 
    
    
    else:
        print ("ERROR")
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    In python2 the input function evaluates the input, and so it needs a valid python expression. If you enter

    a[98

    which is invalid python2 raises an Exception.



    input in python3 behaves like raw_input in python2, and in python3 the raw_input function isn't. It was removed.



    I thought you understood this from previous threads, Nick.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    66
    Rep Power
    2
    Originally Posted by b49P23TIvg
    In python2 the input function evaluates the input, and so it needs a valid python expression. If you enter

    a[98

    which is invalid python2 raises an Exception.



    input in python3 behaves like raw_input in python2, and in python3 the raw_input function isn't. It was removed.



    I thought you understood this from previous threads, Nick.
    I do thanks
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    66
    Rep Power
    2
    Originally Posted by Nick Wyden
    I do thanks
    so it would be illogical to use "else" in this context

IMN logo majestic logo threadwatch logo seochat tools logo