Hello, I am a new CSC 111 student. I have this problem where I am supposed to create "interactive forms", but I'm having trouble figuring out how to do the height, the "time" portion of the form, and it doesn't seem to cooperate interactively. I have the problem and my code posted below. May I please have help with this? I would really appreciate it. Thank you! I've attached the problem and my code is below:

Here is my code:

def main():
    #get data from user
    totalWidth=eval(input("What is the width of the box?"))
    label=input("What is the label of the box under the date?")
    noCandidates=eval(input("How many candidates do you have?"))
    for i in range(noCandidates)
        names.append(input("Candidate 1:", "Candidate 2:", "Candidate 3:")

    #compute the different quantities
    bar           ="+" + '-'*(totalWidth-2) + "+"
    blank         ='|' + ' '*(totalWidth-2)+ "+"
    dateLine      ='| Date:             |'
    dateLine2     ="+-------------------+"
    lineUnderDate ='|                   |'
    dateLine2='|'+' '*noSpacesB4 + dateLine2

   #space things out

   #output the forms for each name
   for name in names:
       noSpaceB4Date=totaNoSpaces+1 -len(dateLine)

       print('|'+name+' '*noSpacesB4Date+dateLine)
       #print blank box
       for i in range(heightBox)


Recommended Answers

All 3 Replies

Clearly the lines 6 until 8 need work, debug this:

noCandidates = 3
for i in range(noCandidates):
    names.append(input("Candidate 1:", "Candidate 2:", "Candidate 3:"))
    print(i+1, names[-1]) # debug

This does not even run first, as you get error:

Traceback (most recent call last):
  File "I:\test\t_inp.py", line 4, in <module>
    names.append(input("Candidate 1:", "Candidate 2:", "Candidate 3:"))
TypeError: input expected at most 1 arguments, got 3

And your goal is to produce inputting three names as per document (after it runs you comment out the debug print to match the requirement):

Candidate 1: Albert
Candidate 2: Roberta
Candidate 3: Alexandra

I would abstract the date box into a function and use string formatting to insert the words date and whatever date is, maybe I'm misunderstanding the problem, but I'd do something like:

def make_label(word):
		lab='| %s:             |\n+-------------------+' % word
		return lab
	except TypeError:
		for words in word:
			slab='| %s:             |\n+-------------------+\n' % words
		return lab

>>> wrdz=('Date','Time')
>>> label=make_label(wrdz)
>>> print(label)
| Date:             |
| Time:             |

also: I see a "potential" issue with this:

for i in range(noCandidates)
        names.append(input("Candidate 1:", "Candidate 2:", "Candidate 3:")

Which just as I posted I saw pytony did too.

Documents sample output has form like this:

|Albert                                     | date:        |
|                                           +--------------+
|                                           | time:        |
|                                           +--------------+
|                                                          |
| Comments:                                                |
|                                                          |
|                                                          |
|                                                          |

If you would like to functionalize this I would have funtion taking old string and having keyword parameters
1) for adding other box at right (remove end of the lines and replace with box)
2) adding another box under old box in string.(leave out first line and concatenate)

Easier way is to take above box and replace the name and white space after with %s formatting with total width of removed part and print it in single multiline string print. For this tasks requirement only name line is changing as input but you should be able to stretch/shrink number of spaces/division line by value based on total width (maybe fixed width for Date/time).

Here one maybe usefull experiment:

>>> print(' %-20s'.ljust(60, ' ').join('++') % 'Tony')
+ Tony                                                                      +
>>> print(' %-20s'.ljust(60, ' ').join('++') % 'DaniWeb')
+ DaniWeb                                                                   +
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.