So I have an assignment about class in python. I've done almost the same as the desired output. But mine prints with parenthesis and comma and in a tuple (I don't even know how its in a tuple). Nowhere do I specify it to be tuple. What did I do wrong?
class buttons:
def __init__(self,word,spaces,border):
self.word = word
self.spaces = spaces
self.border = border
word = "CANCEL"
spaces = 10
border = 'x'
b1 = buttons(word, spaces, border)
print('CANCEL Button Specification:')
print('Button Name:', b1.word)
b1_bord = 1 b1.spaces len(b1.word) b1.spaces 1
print('Number of the border characters for the top and the bottom:', b1_bord)
print('Number of spaces between the left side border and the first character of the button \nname:', b1.spaces)
print('Number of spaces between the right side border and the last character of the button \nname:', b1.spaces)
print('Characters representing the borders:', b1.border)
emp = ''
print(b1.border*b1_bord)
print(f'{b1.border,(emp*spaces),b1.word,(emp*b1.spaces),b1.border}')
print(b1.border*b1_bord)
print("=======================================================")
b2 = buttons("Notify",3, '!')
print('NOTIFY Button Specification:')
print('Button Name:', b2.word)
b2_bord = 1 b2.spaces len(b2.word) b2.spaces 1
print('Number of the border characters for the top and the bottom:', b2_bord)
print('Number of spaces between the left side border and the first character of the button \nname:', b2.spaces)
print('Number of spaces between the right side border and the last character of the button \nname:', b2.spaces)
print('Characters representing the borders:', b2.border)
print(b2.border*b2_bord)
print(f'{b2.border,(emp*b2.spaces),b2.word,(emp*b2.spaces),b2.border}')
print(b2.border*b2_bord)
print("=======================================================")
b3 = buttons('SAVE PROGRESS', 5, '$')
print('SAVE PROGRESS Button Specification:')
print('Button Name:', b3.word)
b3_bord = 1 b3.spaces len(b3.word) b3.spaces 1
print('Number of the border characters for the top and the bottom:', b3_bord)
print('Number of spaces between the left side border and the first character of the button \nname:', b3.spaces)
print('Number of spaces between the right side border and the last character of the button \nname:', b3.spaces)
print('Characters representing the borders:', b3.border)
print(b3.border*b3_bord)
print(f'{b3.border,(emp*b3.spaces),b3.word,(emp*b3.spaces),b3.border}')
print(b3.border*b3_bord)
The output I get:
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
('x', '', 'CANCEL', '', 'x')
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
!!!!!!!!!!!!!!
('!', '', 'Notify', '', '!')
!!!!!!!!!!!!!!
$$$$$$$$$$$$$$$$$$$$$$$$$
('$', '', 'SAVE PROGRESS', '', '$')
$$$$$$$$$$$$$$$$$$$$$$$$$
The output I need:
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
x CANCEL x
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
!!!!!!!!!!!!!!
! Notify !
!!!!!!!!!!!!!!
$$$$$$$$$$$$$$$$$$$$$$$$$
$ SAVE PROGRESS $
$$$$$$$$$$$$$$$$$$$$$$$$$
CodePudding user response:
You can do this
def make_btn(word, space, border):
middle = border word.center(space*2 len(word)) border
edge = border*len(middle)
return f'{edge}\n{middle}\n{edge}'
print(make_btn('CANCEL',10,'x'))
print(make_btn('Notify',3,'!'))
print(make_btn('SAVE PROGRESS',5,'$'))
CodePudding user response:
Firstly,
emp = ''
should be:
emp = ' '
And secondly,
print(f'{b1.border(emp*b1.spaces),b1.word(emp*b1.spaces),b1.border}')
should be:
print(b1.border (emp*spaces) b1.word (emp*b1.spaces) b1.border)
You are using Formatted String Literals with
printf
which is unnecessary in this case. Just use
Repeat the print
statement for b2
and b3
.