Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed
#4
There are better ways of doing this but I'm a bit n0ob myself, but it does the job!

Code:
#! usr/bin/env python

question = raw_input("Ask me something\n")

questionList = ["What are you", "Is this all"]
questionId = 0

answer = [["I'm a Snake, be afraid!", "Second answer for the first question"], ["Nope!"]]

for questions in questionList:
    if question == questions:
        print answer[questionId][0]
    questionId = questionId + 1

questionList is a list/array where you store your questions, questionId is used in the loop to get the right answer for the question.

print answer[questionId][0] would output "I'm a snake.." if the user types "What are you"

I've made this so it can be used with random function to output random answer for a specific question.
Reply


Messages In This Thread
Help needed - by Kenji Harima - 11-05-2009, 04:21 PM
RE: Help needed - by Gaijin - 11-05-2009, 04:37 PM
RE: Help needed - by Kenji Harima - 11-05-2009, 06:59 PM
RE: Help needed - by Gaijin - 11-05-2009, 07:11 PM
RE: Help needed - by Kenji Harima - 11-05-2009, 07:50 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)