Reputation: 33
Hello i want to know how to put these output in 1 line. i know how to do it on this scenario
print("Ayaya", end='')
print("10101", end='')
But this one is little bit different
def stylea():
print(" ___ ")
print(" / | ")
print(" / /| | ")
print(" / ___ | ")
print("/_/ |_| ")
def styleb():
print(" ____ ")
print(" / __ ) ")
print(" / __ | ")
print(" / /_/ / ")
print("/_____/ ")
for c in input("Enter keyword : "):
if c.lower() == "a":
stylea()
if c.lower() == "b":
styleb()
You know what's the output gonna be right? now if i put (, end='') in each print fuction on def it'll messed up the output Thank you.
Upvotes: 0
Views: 133
Reputation: 2226
Here is a pythonic way to do it with letter definitions that are easy to add and modify:
big_a = [
' ___ ',
' / | ',
' / /| | ',
' / ___ | ',
'/_/ |_| ',
]
big_b = [
' ____ ',
' / __ ) ',
' / __ | ',
' / /_/ / ',
'/_____/ ',
]
# map the letters to a character, you could directly put the lines here but this is cleaner
big_chars = {
'a': big_a,
'b': big_b,
}
def big_text(text):
# get the big_letter for each char in the input text
lines = zip(*[big_chars.get(char.lower()) for char in text])
# get the desired output format with lists of lines converted to string
return '\n'.join([''.join(line) for line in lines])
print('the sheep says:')
print(big_text('baaa'))
Output:
the sheep says:
____ ___ ___ ___
/ __ ) / | / | / |
/ __ | / /| | / /| | / /| |
/ /_/ / / ___ | / ___ | / ___ |
/_____/ /_/ |_| /_/ |_| /_/ |_|
Upvotes: 1
Reputation: 54243
In your given code you can't. The solution is get your solution as a list of lines, where each list is
a = [line1, line2, line3, line4, line5]
assert '\n'.join(a) == """\
___
/ |
/ /| |
/ ___ |
/_/ |_| """
then join them together.
def join_on_one_line(*letters, separator=' '):
lines = zip(*letters)
return '\n'.join([separator.join(line) for line in lines])
I'd probably do something like:
# letters.py
__letters = {
"a": """\
___
/ |
/ /| |
/ ___ |
/_/ |_| """,
"b": """\
____
/ __ )
/ __ |
/ /_/ /
/_____/ """,
# etc...
}
def get_letter(letter: str) -> str:
return __letters[letter]
def get_word(word: str, separator: str=' ') -> str:
letters = (get_letter(ch).splitlines() for ch in word)
lines = zip(*letters)
return '\n'.join([separator.join(line) for line in lines])
# main.py
from letters import get_letter, get_word
assert get_letter('a') == """\
___
/ |
/ /| |
/ ___ |
/_/ |_| """
assert get_word('ab') == """\
___ ____
/ | / __ )
/ /| | / __ |
/ ___ | / /_/ /
/_/ |_| /_____/ """
Upvotes: 1
Reputation: 4592
maybe this is what you are looking for
def style(ch):
if ch == "a":
return [
" ___ ",
" / | ",
" / /| | ",
" / ___ | ",
"/_/ |_| ",
]
if ch == "b":
return [
" ____ ",
" / __ ) ",
" / __ | ",
" / /_/ / ",
"/_____/ ",
]
# and other chars
return [
" ",
" ",
" ",
" ",
" ",
]
styles = []
for c in "ab":
styles.append(style(c))
for i in range(0, 5):
line = "".join(list(map(lambda x: x[i], styles)))
print(line)
Upvotes: 2
Reputation: 1
Hi you need to illustrate your expected output. I'll assume you want AB in one line.
print(" ___ ____ ")
print(" / | / __ ) ")
print(" / /| | / __ | ")
print(" / ___ | / /_/ / ")
print("/_/ |_| /_____/ ")
Upvotes: 0