The issue you're seeing is because your routine, printNTimes()
, returns a None value. You say:
allTogether = printNTimes(phrase, number)
print(allTogether)
allTogether
is set to None because printNTimes does not return a value. When you call print(allTogether)
, that's what is printing the None.
It sounds like you intended your printNTimes()
routine to assemble one big string of all the output and return it, which you would then print out via the print(allTogether)
call. But your printNTimes()
routine is calling the print() method and outputing the text then. So, you need to rewrite your printNTimes()
method. Also, note that defining that function inside the loop is not necessary. Once is sufficient. So something like this should suffice:
def printNTimes(s, n):
s_out = ""
for i in range(n):
s_out += s + '\n'
return s_out
str_ = input("Please enter y to start the program: ")
while str_ == 'y':
phrase = input("Enter a string: ")
number = int(input("Enter a positive number: "))
allTogether = printNTimes(phrase, number)
print(allTogether)
print()
str_ = input("Please enter y if you want to continue: ")
print("DONE")
Also note that I renamed your str
variable to str_
. str
is a Python type, a reserved word that should not be reused.