-1

I'm trying to print a line with multiple arguments in python but somehow one specific argument prints before all the others:

star = "*"

def how_many_stars(who):
    for i in range(int(len(who))):
         print(star, end="")


print(" |************** PSEUDO :", player_1.get_name(), how_many_stars(player_1.get_name()),"|")

The argument that prints before is the how_many_stars() The program returns this (I'm using PyCharm community):

***** |************** PSEUDO : Steve None |

(the player_1.get_name is Steve) So we clearly see the 5 stars we wanted but it's not at right position at all ! I already tried to change the order of the arguments but it changes nothing.

Thanks, have a nice day.

  • 1
    When a function is called, it first evaluates its arguments. In this case, the arguments to print includes a call to `how_many_stars(player_1.get_name())`. This causes the print function within function `how_many_stars` to print out stars first. – DarrylG Oct 14 '22 at 13:16

1 Answers1

0

You need to return the string, not print it.

>>> def how_many_stars(who):
...     return star * len(who)
...
>>> print(" |************** PSEUDO :", "David", how_many_stars("Steve"), "|")
|************** PSEUDO : David ***** |
Martin Benes
  • 265
  • 10