Python Forum

Full Version: Homework problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
(Basically the task)
Write a program that displays n flags for a given number n from 1 to 9. The image of one flag has a size of 4 × 4 characters, and between two adjacent flags there is also an empty (from spaces) column. It is allowed to output an empty column after the last flag. Inside each flag, its number must be written - a number from 1 to n.

How the flag looks like:
+___
|1 / 
|__\ 
|    
(My code)
n = int(input())
p_1="+___ "
print(p_1*n, sep='')
for i in range(1,n+1):
    print("|",i," / ",sep='')
p_3="|__\\ "
print(p_3*n)
p_4="|    "
print(p_4*n ,'\n')
So i having a problem when i enter a number, that's bigger than 1 something strange happens:
+___ +___ 
|1 / 
|2 / 
|__\ |__\ 
|    |
There is an end parameter to end, that is displayed after everything else. It defaults to '\n', so normally print always goes to a new line when it's done. Using end = '' in the print in the for loop will solve your problem.