0

I am new to Python. When I printed a line with * at the beginning and end, and an appropriate number of spaces in between, I got it correct but when I tried a different way shorter than the first way, I got * indented by 2 spaces with no reason.

  print("*", end = ""), print(" " * (num), end = ""), print("*") // it works
  *                              *             //1st way sample output
  
  print("*", " " * (num) ,"*")                // 2nd way doesn't work 
  *                                 *         // 2nd way sample output
                                             // the last * is indented by 2 spaces

Any clarification, Thanks

  • Hint: notice how you already know how to use `end=''`, to prevent printing a newline at the end of the line? You read about this **in the documentation**, right? So. Did you try looking at the rest of the documentation, to see if there is anything about printing spaces in between the items? (You did try to check how `print` works by giving it some other inputs that aren't mostly spaces - in order to be able to see how it formats the input items - right?) – Karl Knechtel Jan 11 '23 at 08:50
  • @Karl Knechte I am not allowed to use any uncovered functions of Python right now and that is why I am trying to avoid using `end=" "` but the behavior of `print()` confused me and needed help – Code_Student Jan 11 '23 at 08:57
  • See the duplicate above. You *will* need either `end` and/or `sep`. – deceze Jan 11 '23 at 08:59
  • What do you mean by "uncovered functions"? – Karl Knechtel Jan 11 '23 at 09:00
  • @deceze. we covered right now the first lecture only and didn't go deep and I have to do it somehow without using functions – Code_Student Jan 11 '23 at 09:02
  • @KarlKnechtel, I mean we didn't cover it in the lecture yet – Code_Student Jan 11 '23 at 09:02
  • 2
    You covered `print`, right? That's the only **function** here. `end` and `sep` are **keyword arguments** for the function call. – Karl Knechtel Jan 11 '23 at 09:06

0 Answers0