[Tutor] if statement problems(noob question)

Max Smith sibannac.ms at gmail.com
Mon Apr 8 12:21:57 CEST 2013


Hi, everyone whom might read this, im Max and i am really new to coding,
been going at it for about two weeks using codeacademy and the book "think
python".
when i decided to experiment a little with if statements i ran into the
following problem:

def plus(x,y):
    if x and y == int or float:
        print "The answer is: " + str(x+y)

    else:
        print "not a number"


plus(2,2)
plus("one","two")

concatenates one and two insted of printing "not a number"

i have tried to simplify by not cheacking for float values an i have also
tried.

def plus(x,y):
    if x and y == int or float:
        print "The answer is: " + str(x+y)

    elif x or y != int or float:
        print "not a number"

Am i perhaps missing something with the logic gates?

Any help is greatly appreciated !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130408/9862e576/attachment.html>


More information about the Tutor mailing list