Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed
#1
Hey guys I just started to learn about python and I wanted to make a code that replies an answer to a prelisted question so what should it look like?
Good and Bad you Decide.
SupermanDevlish
Reply
#2
I guess the reply is on some website.
So you should look about the urllib2 module.
Reply
#3
No I want to make a simple py code that when asked a predefined question will answer back with a predefined phrase.
Good and Bad you Decide.
SupermanDevlish
Reply
#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
#5
Thanks dude very appreciated. I'll ask you if I need any more help.
Good and Bad you Decide.
SupermanDevlish
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)