用户提问: ai问卷生成
Ai回答: 创建一个问卷可以通过多种方式实现,包括手动设计、使用现成的问卷工具或编程生成。以下是一个简单的 Python 示例,展示如何用代码生成一个基本的问卷:
python
class Question:
def __init__(self, question_text, options=None):
self.question_text = question_text
self.options = options if options else []
def ask(self):
print(self.question_text)
for idx, option in enumerate(self.options, 1):
print(f{idx}、{option})
return input(Your answer: )
class Questionnaire:
def __init__(self, title=Survey):
self.title = title
self.questions = []
def add_question(self, question):
self.questions.append(question)
def run(self):
print(f {self.title} )
answers = {}
for question in self.questions:
answer = question.ask()
answers[question.question_text] = answer
return answers
Example usage:
if __name__ == __main__:
Create questions
q1 = Question(What is your age?, [Under 18, 18-30, 31-45, Over 45])
q2 = Question(What is your gender?, [Male, Female, Other])
q3 = Question(How satisfied are you with the service?, [Very Dissatisfied, Dissatisfied, Neutral, Satisfied, Very Satisfied])
Create questionnaire
survey = Questionnaire(Customer Satisfaction Survey)
survey.add_question(q1)
survey.add_question(q2)
survey.add_question(q3)
Run the survey
results = survey.run()
print(\n Results )
for question, answer in results.items():
print(f{question}: {answer})
这个示例代码定义了两个类:`Question` 和 `Questionnaire`。`Question` 类用于表示单个问题及其选项,而 `Questionnaire` 类则管理一组问题并运行问卷调查。
你可以根据需要修改和扩展这些类来适应更复杂的问卷需求,例如添加验证逻辑、支持多选题等。此外,你还可以将结果保存到文件中或数据库里以供进一步分析。
0
IP地址: 132.231.250.49
搜索次数: 5
提问时间: 2025-04-21 09:39:14
热门提问:
ai创曲
国融融鑫混合C
免费ai写歌网站
个人开发者 ai
浙商惠利纯债A