Ask coding questions

← Back to all posts
How should I improve this?-Python
LuckyOreos (203)

This is basically a chat bot program which lets you talk to Star Wars Characters!!! It’s in progress and I might submit it into the AI competition!!! But since I’m learning Python at a pretty slow pace, mainly because of COVID. I need help. My main question about this program is “When you are chatting with the Chat Bots in this program, How do I program it so that you can ask more than 1 question and don’t have to like press Run again to ask another one?”

Answered by EpicGamer007 (1794) [earned 5 cycles]
View Answer
LuckyOreos (203)

Thanks epicgamer007 and everyone

brandosha (20)

You can clean up your code a lot by using dictionaries:

You can do something like this

Notice how I used .get() instead of indexing. This enables a default response instead of throwing an error.

Also notice how it is in a while True loop so it will repeatedly ask for input.


don't use so many ifs. Try using elifs too.

LuckyOreos (203)

@RYANTADIPARTHI thank u I’ll try that I’m also doing this assignment for school so I want it to be perfect or near perfect. And I’m going to try that