I am trying to make a box where the user inputs the width, height, what kind of symbol the box should be made out of and the fill(inside the box). I am a new python coder, so any suggestions would be great, but the more novice level responses the better so i may learn and not skip into far advance techniques.
def main():
width = print(int("Please enter the width of the box: "))
height = print(int("Please enter the height of the box: "))
symbol = print("Please enter the symbol for the box outline: ")
fill = print("Please enter the symbol for the box fill: ")
for a in range(width):
for b in range(height):
if i in #some condition here
print(symbol)
else:
print(fill)
main()
My projected input should be:
width: 4
height: 4
symbol: #
fill:1
####
#11#
#11#
####
def main():
# input is your friend here
width = input("Please enter the width of the box: ")
#width = print(int("Please enter the width of the box: "))
# input etc..
height = print(int("Please enter the height of the box: "))
symbol = print("Please enter the symbol for the box outline: ")
fill = print("Please enter the symbol for the box fill: ")
#since you'll be printing rows of text you should probably flip these loops
for row in range(height):
#for a in range(width):
for col in range(width):
#for b in range(height):
# i ??? huh where did this come from ?
#if i in [0, width-1] or [0, height-1]:
# descriptive variables can only help
if row in [0,height-1] or col in [0,width-1]:
print(symbol)
else:
print(fill)
Use input("Enter number")
to get input from the user. You should first loop on height then on width. To print with no new-line use end=""
as a parameter to print
. You used i
instead of b
and a
. That's about it I think. Next time ask more specific questions.
def main():
width = int(input("Please enter the width of the box: "))
height = int(input("Please enter the height of the box: "))
symbol = input("Please enter the symbol for the box outline: ")
fill = input("Please enter the symbol for the box fill: ")
dictionary = []
for row in range(height):
for col in range(width):
if row in [0, height-1] or col in [0, width-1]:
dictionary.append(symbol)
else:
dictionary.append(fill)
def slice_per(source, step):
return [source[i::step] for i in range(step)]
sliced = slice_per(dictionary, width)
for x in range(len(sliced)):
print("".join(sliced[x]), end="\n")
main()
Output - 5, 5, #, 0
#####
#000#
#000#
#000#
#####
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.