Write a python script that:
- Demonstrates the original (built-in) method
- Uses a function that you wrote that replicates the same behavior, without calling the method
For example, for the repetition operator, *:
def strRepetition( str1, num):
newStr = ""
for i in range( num):
newStr += str1
return newStr
def main():
strVar = "Ha"
num = 5
result = strVar * num
print( strVar, " * ", num, ": ", result, sep='')
result = strRepetition( strVar, num)
print( "strRepetition(", strVar, ", ", num, "): ", result, sep='')
main()
Output:
Ha * 5: HaHaHaHaHa
strRepetition(Ha, 5): HaHaHaHaHa