def star():
print("***")
def slash():
print("///")
def main():
print(star(), slash())
main()
I would like this to print "***///" but
I am unable to print them on the same line without getting an error.
def star():
print("***")
def slash():
print("///")
def main():
print(star(), slash())
main()
I would like this to print "***///" but
I am unable to print them on the same line without getting an error.
Your functions star()
and slash()
call print()
and they don't return any value. But your function main()
is trying to print the values they return. You need to make up your mind where control of the printing is going to be. And it probably shouldn't be in star()
and slash()
because you want control over whether the output is on one line or not, and those functions can't tell what is also on the line. You could do it this way:
def star():
return "***"
def slash():
return "///"
def main():
print(star(), slash())
main()
What you really want is:
def star():
return "***"
def slash():
return "///"
def main():
print(star(), slash(), sep='')
main()
You need to return the string you want to print. Otherwise, you are will get:
***
///
None None
You wouldn't run print(print('value'))
but that is what you are doing here. Rather you should say that you want the function you are calling to the first value and the second with another value. Then you can simply add them together.
You could use the return
statement and create a variable.
For example:
def star():
return "***"
def slash():
return "///"
def main():
a = star() + slash()
print(a)
main()
You can read about them here
Try this
def star():
print("***", end = "")
def slash():
print("///")
def main():
print(star(), slash())
main()