Click here to Skip to main content
15,041,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the problem is in a survey/test creation and execution program.it lets the person choose how many people will be doing it and the questions are in one input using for loops but it needs a way to sort the answers to each question in lists
for each person.is there a way to create lists depending on how many people are taking the survey and append the lists with the answers that those people give?

What I have tried:

context-this is the entire programm up to the point where the answer goes:

Python
<pre>class colour:
    PURPLE = '\033[95m'
    CYAN = '\033[96m'
    DARKCYAN = '\033[36m'
    BLUE = '\033[94m'
    GREEN = '\033[92m'
    YELLOW = '\033[93m'
    RED = '\033[91m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
    END = '\033[0m'

print(colour.BOLD + colour.UNDERLINE + 'Survey Maker and Executer' + colour.END)
print(colour.BLUE + colour.BOLD + '''type "help" for a step by step description of how this program works.
type "next" to continue.
Have Fun!
''' + colour.END)
help_or_next = input("type help or next: ")
if help_or_next == ("help").lower():
    print(colour.YELLOW + colour.BOLD + "description of how the program works" + colour.END)
    print("""
part#1 = this part of the survey creation will ask you to input the number of
people you want to take this survey. it will then ask you to input titles or names for each of these
purely to have a heading under the results of each survey.
part#2 = this part of the survey creation will ask you how many questions will be in your
survey then, based on that it will a you to type out each question one at a time.
part#3 = this part will be a final stopping point before the survey begins
""")
print(colour.BOLD + colour.GREEN + "part#1- number of surveys and names" + colour.END)
names_or_headings = [] 
i = 1
while i < 2:
    number_of_surveys = input("number of surveys to be done up to 10: ")
    limit = ("abcdefg")
    if int(number_of_surveys) == 1:
        limit = ("a")
        i = 3
    elif int(number_of_surveys) == 2:
        limit = ("ab")
        i = 3
    elif int(number_of_surveys) == 3:
        limit = ("abc")
        i = 3
    elif int(number_of_surveys) == 4:
        limit = ("abcd")
        i = 3
    elif int(number_of_surveys) == 5:
        limit = ("abcde")
        i = 3
    elif int(number_of_surveys) == 6:
        limit = ("abcdef")
        i = 3
    elif int(number_of_surveys) == 7:
        limit = ("abcdefg")
        i = 3
    elif int(number_of_surveys) == 8:
        limit = ("abcdefgh")
        i = 3
    elif int(number_of_surveys) == 9:
        limit = ("abcdefghi")
        i = 3
    elif int(number_of_surveys) == 10:
        limit = ("abcdefghij")
        i = 3
    else:
        print("i don't understand that, please try again")
for charecters in limit:
    name_or_headings_input = input("Enter the names/headings of the different survey attempts 1 at a time in the desired order: ")
    names_or_headings.append(name_or_headings_input)
unnanswered = True
print(colour.BOLD + colour.GREEN + "part#2- question creation" + colour.END)
questions = []
while unnanswered == True:
    Number_of_questions = input("input a number up to 10 for the questions to be in survey: ")
    if int(Number_of_questions) == 1:
        limit = ("a")
        unnanswered = False
    elif int(Number_of_questions) == 2:
        limit = ("ab")
        unnanswered = False
    elif int(Number_of_questions) == 3:
        limit = ("abc")
        unnanswered = False
    elif int(Number_of_questions) == 4:
        limit = ("abcd")
        unnanswered = False
    elif int(Number_of_questions) == 5:
        limit = ("abcde")
        unnanswered = False
    elif int(Number_of_questions) == 6:
        limit = ("abcdef")
        unnanswered = False
    elif int(Number_of_questions) == 7:
        limit = ("abcdefg")
        unnanswered = False
    elif int(Number_of_questions) == 8:
        limit = ("abcdefgh")
        unnanswered = False
    elif int(Number_of_questions) == 9:
        limit = ("abcdefghi")
        unnanswered = False
    elif int(Number_of_questions) == 10:
        limit = ("abcdefghij")
        unnanswered = False
    else:
        print("I don't understand that, please try again.")
    for charecters in limit:
        questions_input = input("Enter your questions one by one in order: ")
        questions.append(questions_input)
print(colour.BOLD + colour.GREEN + "part#3 - starting" + colour.END)
print("make sure the people who are taking the survey/quiz are taking it in the order you gave.")
start = input("type start when you are ready: ")
for each_survey in range(0, number_of_surveys):
    for each_question in questions:
        answering = input(item)
Python
<pre lang="Python">
Posted
Updated 7-Apr-21 2:35am
v3
Comments
Richard MacCutchan 7-Apr-21 6:47am
   
There is not really enough information to fully understand the question. In the above code you throw away all the answers which is obviously not what you want.

1 solution

You can simplify that code considerably, and also correct the saving of numbers as strings:
Python
names_or_headings = [] 
i = 1
while i < 2:
    number_of_surveys = int(input("number of surveys to be done up to 10: ")) # convert to int here
    if number_of_surveys == 0 or number_of_surveys > 10:
        print("i don't understand that, please try again")
    else:
        i = 2
for x in range(number_of_surveys):
    name_or_headings_input = input("Enter the names/headings of the different survey attempts 1 at a time in the desired order: ")
    names_or_headings.append(name_or_headings_input)

unnanswered = True
print(colour.BOLD + colour.GREEN + "part#2- question creation" + colour.END)
questions = []
while unnanswered == True:
    Number_of_questions = int(input("input a number up to 10 for the questions to be in survey: "))
    if Number_of_questions == 0 or Number_of_questions > 10:
        print("I don't understand that, please try again.")
    else:
        for x in range(Number_of_questions):
            questions_input = input("Enter your questions one by one in order: ")
            questions.append(questions_input)
            unnanswered = False

print(colour.BOLD + colour.GREEN + "part#3 - starting" + colour.END)
print("make sure the people who are taking the survey/quiz are taking it in the order you gave.")

#
# the following code fails as "item" has not been declared anywhere
#
start = input("type start when you are ready: ")
for each_survey in range(number_of_surveys):
    for each_question in questions:
        answering = input(item)

Apart from the fact that item is not defined (you probably meant to use each_question), the answer is not saved anywhere.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900