multiply string by number python -


so have program takes 1 argument, integer num. supposed return number repeats digits of num 3 times. if argument not integer, function should return none.

for example:

for input argument "hello!", should return none, because input argument string.

for input argument "23", should return none, because input argument string. .

for input argument 12.34, should return none, because input argument float. .

for input argument 1, should return 111 or argument 241, should return 241241241.

i don't know i'm doing wrong in mine, appreciated!

def repeat_number(num):     if num type(str) , type(float):         return none     else:         return str(num) * 3 

you're close. there 2 different problems here.

first, shouldn't have type check (duck typing), if must, right:

if not isinstance(num, int):   return none 

this returns none if argument isn't integer. repeating number, need turn string number:

return int(str(num) * 3) 

full code:

def repeat_number(num):   if not isinstance(num, int):     return none   else:     return int(str(num) * 3) 

Popular posts from this blog