-1
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.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 3
    Possible duplicate of [Why would you use the return statement in Python?](https://stackoverflow.com/questions/7129285/why-would-you-use-the-return-statement-in-python) – jonrsharpe Jan 29 '18 at 22:28

4 Answers4

2

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()
BoarGules
  • 16,440
  • 2
  • 27
  • 44
1

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
thyago stall
  • 1,654
  • 3
  • 16
  • 30
1

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

Xantium
  • 11,201
  • 10
  • 62
  • 89
0

Try this

def star():

        print("***", end = "")

    def slash():

        print("///")

    def main():

        print(star(), slash())

    main()
Mike Bagg
  • 9
  • 2