Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework problem
#1
(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 / 
|__\ |__\ 
|    |
Reply
#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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with a formula 1 kind of homework claroque 2 1,346 Jun-20-2023, 09:58 PM
Last Post: claroque
  Bakery Problem.. Can you Help My Homework Cemvrs 1 2,318 Jan-14-2022, 05:47 PM
Last Post: Yoriz
  Need help with a homework problem on logical operators voodoo 3 4,537 Jun-28-2019, 03:45 PM
Last Post: jefsummers
  Homework Problem csascott 1 2,231 Oct-27-2018, 04:44 AM
Last Post: scidam
  Homework Problem Travisbulls34 1 2,910 Sep-11-2018, 04:04 PM
Last Post: ichabod801
  Help with homework problem - iterating a function midnitetots12 4 3,444 Feb-21-2018, 10:51 PM
Last Post: nilamo
  Problem with a homework Samuelcu 2 2,794 Feb-03-2018, 01:39 PM
Last Post: Samuelcu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020