0

I'm learning python on singpath. And I trying to difficulty hard.

Anyways, I have to return values str,float,int.

I succeed almost question but I can't solve only 2 questions.

these:

>>>str_int('hi',2)  
   hihi 
>>>str_int(3,'bye') 
   byebyebye    

but in my case:

>>>str_int('hi',2)
   hi2
>>>str_int(3,'bye')
   3bye

I can't understand why my code return that values without error.

this is my code:

def str_int(a,b):
if type(a) == type(b):
    return a+b
elif type(a) or type(b) == str:
    if type(a) and type(b) == float:
        return a+b
    elif type(a) or type(b) == float:
        return str(a)+str(b)
    return a*b
  • Also, use [`isinstance`](https://docs.python.org/3/library/functions.html#isinstance). – jonrsharpe Mar 02 '15 at 14:55
  • I'm fairly certain that `if type(a) or type(b) == str` is not equivalent to `if type(a) == str or type(b) == str`, which is probably what you really meant... – twalberg Mar 02 '15 at 15:53

0 Answers0