[Tutor] if statement problems(noob question)

Woody 544 woody544 at gmail.com
Mon Apr 8 12:37:41 CEST 2013


Max,

You've made the arguments a string (so never a number) in:

print "The answer is: " + str(x+y)

MJ
On Apr 8, 2013 6:23 AM, "Max Smith" <sibannac.ms at gmail.com> wrote:

> 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 !
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130408/456af2ba/attachment.html>


More information about the Tutor mailing list