-1

Im trying to reproduce this c for loop (below) in python. but the result displays each iteration on a new line is there a way to print and not start a new line?

Code in C++:

int pennies = 10;
for (int i = 1; i <= 6; i = i + 1)//cout "o" for every penny
{
    cout << "o";
}

output:

oooooooooo

And in python I have tried:

pennies = 10
for i in range(pennies):
    print("o")

output:

o
o
o
o
o
o
o
o
o
o
Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
JSouthward
  • 102
  • 10

1 Answers1

-1

Specify end to the print command:

print("o", end='')
Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Jim B.
  • 4,512
  • 3
  • 25
  • 53