Home > Software design >  How to have a blank line between sets of print statements?
How to have a blank line between sets of print statements?

Time:01-31

I am having this small issue where my code is not printing any blanks between sets of print statements.

    print(countries[11], file=output_file)
    print(countries[17], file=output_file)

    print("Continent:", continents[3], file=output_file)
    print("Currency:", currency[3], file=output_file)

There should be a blank line between these two sets, but there isn't. Any insight would be greatly appreciated.

I have tried using \n but I do not know where to put it since my code is a little complicated (to me at least). I was expecting it to print kinda like this, with a blank line between them. print statement print statement

print statement print statement

CodePudding user response:

Here's a quick and simple way to do what you are trying to achieve

print(countries[11], file=output_file)
print(countries[17], file=output_file)
print()
print("Continent:", continents[3], file=output_file)
print("Currency:", currency[3], file=output_file)

CodePudding user response:

You could probably try rewriting the 3rd line like this. print("\nContinent:", continents[3], file=output_file)

CodePudding user response:

there are a couple ways you could do this. You can either do something like printing a line in between manually

print(countries[11], file=output_file)
print(countries[17], file=output_file)
print()
print("Continent:", continents[3], file=output_file)
print("Currency:", currency[3], file=output_file)

or you could write it into the end parameter of the print statement like this:

print(countries[11], file=output_file)
print(countries[17], file=output_file, end="\n\n") # \n\n just puts a second line break after the first

print("Continent:", continents[3], file=output_file)
print("Currency:", currency[3], file=output_file)
  • Related