Day 031 - Project 31 : f-string User Interfaces

If you have any questions, comments or issues with this project please post them here!

I went retro :mirror_ball: and recreated two classic user interfaces. Can you guess what they are?

https://replit.com/@JackAdem/Day-031-Project-31-f-string-User-Interfaces?v=1

Day 31 of #Replit100DaysOfCode #100DaysOfCode.

1 Like

Question: Why is this printing to 2 new lines? How do I make Armbook appear on the line after weclome to?

Repl link: main.py - Day31_100 days - Replit

#ARMBOOK
print("\033[1;0m")
print("\n\n\n\n\n\n\n")
welcome="WELCOME TO"
armbook="--  ARMBOOK  --"
welcome1=f"{welcome:^70}"
print(welcome1)
armbook1=f"{armbook:^70}"
print("\033[1;34m",armbook1)

@DukeTI please avoid pinging people not already involved in posts.

The reason your code is printing two lines is because print will add a new line to the end of the text by default. If you’d like it to not do this, add end="" to the print statement.

For example:

print("A")
print("B")

Outputs:

A
B

However:

print("A", end="")
print("B")

Outputs:

AB
2 Likes

The solution presented by Firepup seems right to me. Let us know if it doesn’t work. Alternatively, you could put both lines in one print statement, like this:

#ARMBOOK
print("\033[1;0m")
print("\n\n\n\n\n\n\n")
welcome="WELCOME TO"
armbook="--  ARMBOOK  --"
welcome1=f"{welcome:^70}"
armbook1=f"{armbook:^70}"
print(welcome1 + "\n" +  "\033[1;34m" + armbook1)
2 Likes

Unsure why my code to shift the text “queen” to the right is not working. Shouldn’t appending : >5 to the text string variable shift it right 5 spaces? However, it is hard left ruled. I can fix it if I just manually insert 5 spaces but this is inelegant and I want to understand why this isn’t working. Code below, thanks. Haven’t watched the solution video yet, trying to avoid that if at all possible.

def red(text):
  return "\033[0;31m" + text + "\033[0m"


def blue(text):
  return "\033[0;34m" + text + "\033[0m"


def green(text):
  return "\033[0;32m" + text + "\033[0m"


def purple(text):
  return "\033[0;35m" + text + "\033[0m"


def yellow(text):
  return "\033[1;33m" + text + "\033[0m"


text = f"{red('=')}{'='}{blue('=')}{yellow(' Music App ')}{blue('=')}{'='}{red('=')}"
text2 = f"{yellow('Queen')}"
width = 80
print(f"{text.center(width)}", end="\n")
print("🔥▶️  Radio Gaga", end="\n")
print(f"{text2: >5}", end="\n\n")

no shifting will be done because text2 already takes up more than 5 chars

2 Likes

Thanks! changing the 5 to 21 to account for the 16 chars in text2 has resolved the issue.

1 Like