Skip to content

Commit

Permalink
Merge pull request isaacg1#232 from Jim-Bar/multiply-strings-negative
Browse files Browse the repository at this point in the history
Multiplying a string by a negative number returns the reversed string multiplied
  • Loading branch information
isaacg1 authored Jul 12, 2017
2 parents 4709295 + e42192d commit 93b6d07
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,18 @@ def times(a, b):
return[''.join(pair) for pair in prod]
else:
return [list(pair) for pair in prod]
if is_num(a) and is_num(b) or\
isinstance(a, int) and is_seq(b) or\
is_seq(a) and isinstance(b, int):
if is_num(a) and is_num(b):
return a * b
if isinstance(a, int) and is_seq(b):
if a < 0:
return - a * b[::-1]
else:
return a * b
if is_seq(a) and isinstance(b, int):
if b < 0:
return -b * a[::-1]
else:
return a * b
return unknown_types(times, "*", a, b)
environment['times'] = times

Expand Down

0 comments on commit 93b6d07

Please sign in to comment.