python program to engage a user in conversation.requirements are

a. firts question should ask the user for name .this name should then be used with the following questions
b.Ask 4 more questions
c. Each question should have 3 possible answers.That us option A,B or C(only)
d. Have a different comment for each user response

i have a example something like this
PC: hi there.whats your name?
user: some name
PC: nice to meet you (name).Do you like python?(A= its great,B=its ok,C=its rotten)
user:A
PC: That good(name).I like it too.Do you play games?(A=outdoorgames,B= only indoor, c= noway)
user: B

please help me with this its a small project for me

Recommended Answers

All 2 Replies

Why not keep a list of lists for responses corresponding to each user answer? Such as:

responses = [
    ["Q1, A", "Q1, B", "Q1, C" ],
    ["Q2, A", "Q2, B", "Q2, C" ],
    ["Q3, A", "Q3, B", "Q3, C" ]
]

and if you collect the user input as an integer, and you keep track of the number of the question you're asking (0, 1, 2, etc.) you can just call up the appropriate response to print by saying:

print responses[questionNumber][userAnswer]

Collecting the user input could use a function that returns an integer from 0 to 2 (inclusive) depending on if the user gave A, B, or C as the answer. Here's an example:

def getAnswer():
    while 1:
        ans = raw_input( "Enter answer:  " ).upper()
        if ans == "A": return 0
        elif ans == "B": return 1
        elif ans == "C": return 2

answer = getAnswer()  # equals 0, 1, or 2 corresponding to A, B, C

There are better ways of writing this, but the above is a very basic and easy to understand form of it. The above does account for A, B or C not being given at all, and loops until it receives one of the letters.

The above isn't much, but it should be a good start on this sort of project. This sounds exactly like a homework assignment, so as such, I won't be giving any more in-depth tips, but I'll try to help a bit more if needed.

P.S. This is more on a personal note, but please at least put a bit of effort into your post, so at the bare-minimum it seems semi-intelligent (i.e. correct the horrendous typing and grammar). If you're requesting a favour (like help for homework), at least show some effort yourself. Thanks :P

commented: I like your style +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.