Help with making a Box!

homework

#1

So I have an assignment to do and our goal is to create a box (Hollow) with the user given output. We need to use print_line(), get_size(), get_char(). I have been trying to fix it up but when I run the program under print_box() and enter the answers, I cant get a box, here is what I have so far:

def print_line(ch, size):
    print(ch)
    for index in range(4):
        print(ch, end ="")
    print(ch)

def get_size():
    n = int(input("Enter a number between 3 and 8: "))
    while n < 3:
        n = int(input("Wrong, enter a number between 3 and 8: "))
        return n

def get_char():
    ch = input("Enter a character (* or -): ")
    while ch not in '*-':
        ch = input("Please try again: ")
        return ch
    

def print_box():
    size = get_size()
    ch = get_char()
    print_line(ch, size)
    
    print_line(ch, size)

#2
def print_line(ch, size):
    print(ch)
    for index in range(4):

Did you mean to use size where you have 4?

Is the last function intended to have two print statement?

Is the return statement supposed to have that much indentation in get_char()? Likewise in get_size?


#3

In all accounts we hope you haven’t given up. This is what I’ve come up with in the meantime that might prove insightful, or fun, nonetheless.

def print_line(char, length):
  print (char * int(length * 2))

def get_height(max_size=31):
  try:
    n = 0
    while n not in range(3, max_size + 1):
      n = int(input("Enter height (max=" + str(max_size) + ")"))
    return n - 1
  except ValueError:
    return get_height()

def get_char(options="*-"):
  while True:
    char = input("Choose from " + options)
    if char in options: return char
    
def set_line(char, size):
  char = '|' if char == '-' else char
  return char + (' ' * (size - 1) * 2) + char
def print_box():
  size = get_height()
  char = get_char()
  line = set_line(char, size)
  print_line(char, size)
  for _ in range(1, size): print (line)
  print_line(char, size)
Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
   
 > print_box()
 Enter height (max=31) 3
 Choose from *- *
 ****
 *  *
 ****
 > print_box()
 Enter height (max=31) 4
 Choose from *- *
 ******
 *    *
 *    *
 ******
 > print_box()
 Enter height (max=31) 5
 Choose from *- *
 ********
 *      *
 *      *
 *      *
 ********

https://repl.it/Mfo9/2


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.