简体   繁体   中英

How to assign values to answers in a questionnaire in python?

I have a questionnaire with multiple answers choices like "nothing", "very little", "a bit", "partially", "a lot" "totally". To multiple questions.

I'm doing a correlation analysis (for start) on this and two other tests, with different but similar answers choices.

I'm trying to convert them to values with "weight" so that they matter on the calculations. Nothing(1), very little(2), totally(6) and etc... Is it possible to do this in a way that will be permanent on the csv?

No, without programming all of the words in before hand this would be impossible. But perhaps instead prompt the user to enter a number between 1 and 10. This would allow you to preform your correlation analysis more effectively.

However if would be possible to use a dictionary:

answer = input("Question: ")
answer_choices = {'Nothing':1, 'very little':2, 'totally':6}
if answer in answer_choices:
    number = answer_choices[answer]
else:
    raise ValueError

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM