Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Weather-Music-Chatbot/randomQuestion.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
86 lines (63 sloc)
3.91 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wikipedia # use wikipedia module to make the bot reply to certain questions more smoothly | |
import random | |
from storeInput import storeInput | |
from quiz import quiz | |
# ++++++++++++++++++++++++++++++++++++++++++++ ALL ORIGINAL CODE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
def not_understand(): # NOT USED - chat feels more natural if the bot does not reply with an automated message every time something | |
print("Unfortunately I couldn't understand what you meant to say... could you repeat again? Be careful" | |
" with wording.") | |
# response for when bot doesn't understand what is asked | |
def answer(): # Function that allows the bot to respond according to the strings in the question (words list) | |
words = storeInput() | |
# How are you | |
if "how" and "are" and "you" in words: | |
how_response = ["well", "fine", "okay", "so-so, not bad at all", "great", "pretty good"] | |
print("I am doing " + random.choice(how_response) + random.choice( | |
[".", "!"])) # With the random module, we can make the responses more dynamic | |
# Favorites, with various options which makes the bot feel more realistic rather than robotic | |
elif "what" and ("favorite" or "favourite") and not "least" in words: | |
if "sport" in words: | |
fav_sport = ["soccer", "volleyball", "korfball", "rugby", "dodgeball"] | |
print("One of my favorite sports is " + random.choice(fav_sport) + ".") | |
elif "film" in words: | |
fav_movie = ["American Psycho", "Parasite", "Scream", "Avengers Infinity War", "The Shining", | |
"Drive (2011)"] | |
print("I like " + random.choice(fav_movie) + " a lot.") | |
elif "video-game" in words: | |
fav_game = ["Metal Gear Solid 3", "Xenoblade Chronicles", "428 Shibuya Scramble", "NieR Automata", | |
"Persona 4 Golden", | |
"Gravity Rush", "Tekken 5", "Fire Emblem Echoes", "Guilty Gear", "Under Night In Birth", | |
"Silent Hill", | |
"Smash Ultimate", "Pokemon Gen 5", "Zero Escape"] # great games, great games | |
print("Have you ever heard of " + random.choice(fav_game) + "? It is one of my favorites.") | |
elif "anime" in words: | |
fav_ani = ["Hunter x Hunter", "Casshern Sins", "Hyouka", "Code Geass", "Daily Lives of Highschool Boys"] | |
print("I enjoyed watching " + random.choice(fav_ani) + ".") | |
if "what" and ("favorite" or "favourite") and "least" in words: | |
if "sport" in words: | |
print("The sport I like the least is probably basketball.") | |
elif "film" in words: | |
print("I don't really have a movie I really dislike.") | |
elif "video-game" in words: | |
print("I really did not enjoy Call of Duty Vanguard.") | |
elif "anime" in words: | |
print("I have not watched enough anime to provide a good answer!") | |
# Wikipedia search | |
elif "wikipedia" and "search" in words: | |
word = input("If you want me to do a wikipedia search, could you tell me which thing you want me to search in " | |
"particular? If you don't really want to search anything you can just say no.\n") | |
if word == ("no" or "nope" or "nah" or "don't" or "dont"): | |
pass | |
else: | |
try: | |
print(wikipedia.summary(word, | |
2)) # Prints the first 2 sentences of a wikipedia article with the same name as the input | |
except wikipedia.exceptions.PageError: # Makes it so a non-corresponding page does not crash the program | |
print("I couldn't quite understand that!") | |
# shutdown | |
if "shutdown" in words: | |
exit() # Turns programme off | |
# Quiz | |
if "quiz" in words: # Initiates quiz | |
quiz(0, 0) | |
# ++++++++++++++++++++++++++++++++++++++++++++ ALL ORIGINAL CODE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |