#---------------------------------------------------------------------- # February 13, 2019 #---------------------------------------------------------------------- #********************************************************************** # Task: Write a function called Bang that takes in one parameter # called N (int), returns a string containing that many exclamation # points. # Bang(4) the result will be "!!!!" # Bang(2) the result will be "!!" # Bang(0) the result will be "" #********************************************************************** #---------------------------------------------------------------------- # Solution #1: Start with an empty string, and keep concatenating # "!" characters until the string length is N. If N==0 then the # string returned will be empty. #---------------------------------------------------------------------- def Bang1 (N): S = "" while len(S) < N: S = S + "!" return S #---------------------------------------------------------------------- # Solution #2: Start with an empty string, and then use a counter-loop # to add exactly the right number of "!" characters to the string. # As before, if N==0 then string returned will be empty. #---------------------------------------------------------------------- def Bang2 (N): S = "" Counter = 1 while Counter <= N: S = S + "!" Counter = Counter + 1 return S