Trying To make a function in Python
I want to make a function called
helloWorld() that will return "Hello World!" if it has no input and whatever string you put if it does. It also has a stack argument that, if set to true, will cause the string to be printed in a column. If you set stack to true and set c to any number, that number of characters should be on each line, and no line should repeat characters. I currently have this code:
def helloWorld(text="Hello World!",stack=False,c=1,printResult=False):
# If the user inputs a value that isn't a string, make it a string and assign it to "s".
s=str(text)
li=0
# Check if the "stack" argument is True.
if stack==True:
# Set char to be the amount of lines that need to be returned.
char=range(int(len(s)/c))
# Set up the first line.
r=[s[:c]]
# Loop through char to print each line.
for x in char:
if x==0:
continue
else:
r.insert(len(r),s[x:x*3])
li=+1
# If "stack" is False then set r to be s.
else:
r=s
line=range(li)
if printResult==True:
for x in line:
print(r[x])
else:
return(r)
print(helloWorld(stack=True,c=3,printResult=False))
if printResult is false like shown, then it just doesn't print the result automatically and instead returns a list. printResult being set to true should make it print the text in a column if it is set to do that, but it doesn't seem to do that.
1 Answer
1 year ago by AxolotlAnimates
you can help in the test plss
1 year ago by Như Ánh