-2

So I mainly code in Python however have coded using C# due to my major one thing in C# is being able to write on the same line using "Write" for example

  int Num_Asteriks = 20.    
  for (int x = 0; x < NUM_ASTERIKS; ++x)
     Write("*");//Creates the top boarder for the company motto

that was in C#. Im wondering if there is a way to do this in python ive tried the code listed below with no luck. It just prints on multiple lines

x = 0
asteriks = 15
while x != asteriks:
    print('*',)
SpacedOutKID
  • 95
  • 1
  • 14

1 Answers1

1

by default end='\n' which means a newline

this may work.

for i in range(20):
    print("*", end='')
Abdeslem SMAHI
  • 453
  • 2
  • 12
  • This worked actually, don't know why I didn't think of this. Can you explain the end = ' ' part for me? what exactly does that do? – SpacedOutKID Jul 24 '20 at 01:10
  • 1
    @SpacedOutKID end=' ' means, where you want to start writing the 2nd element, by default it is "in new line" (end='\n'), if you don't want the 2nd element to be printed in new line you have to specify that by writing end=' ' so that the 2nd element prints after a space not in new line. – lovish kumar Jul 24 '20 at 01:16
  • 1
    when you print something the python interpreter add the character you specify in the end argument. By default, it is \n which means go to a new line. In your case we change it to "" so it stay on the same line. – Abdeslem SMAHI Jul 24 '20 at 01:16
  • @lovishkumar I appreciate the explanation! helped a lot – SpacedOutKID Jul 24 '20 at 12:52
  • @AbdeslemSMAHI Wanted to say thanks to you too only could tag one tho, I appreciate the help! – SpacedOutKID Jul 24 '20 at 12:52