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?
ChatBot/main.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
90 lines (84 sloc)
5.5 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 sys #importing functions | |
from Check import checky,checkn,checkw | |
from weather import Weather, Unit ##############REQUIRES "pip install weather-api"############# | |
from VideoGames import VideoGames | |
from Sunny import Phone | |
from josephAgi import Sports | |
#from music import Music | |
#Start of greetings code | |
greet = True #Boolean variable used to loop greetings code | |
while greet == True: | |
name = "" | |
while name == "": | |
name = input("Hello what is your name? ") #Asking for name input | |
if name != "": | |
name = name.capitalize() #Capitalize the name | |
print("Hello ",name) | |
else: #If nothing is inputted | |
print("Please enter a name") | |
age = input("How old are you? ") #Asking for age input | |
passa = False #Boolean variable used for age input and check | |
while passa == False: | |
try: | |
age = int(age) | |
if age <=0 or age >= 110: #Different output depending on the age given | |
age = input("That's not possible, how old are you? ") | |
elif age < 20: | |
print("Wow, so young") | |
passa = True | |
elif age == 20: | |
print("Wow same!!") | |
passa = True | |
else: | |
diff = age - 20 | |
print("You're ", diff ," years older than me") | |
passa = True | |
except ValueError: #Exception if input can't be turned into integer | |
age = input("Age is a number, how old are you? ") | |
passb = False #Boolean variable used for yes/no check | |
yn = input("So your name is "+ name +" and you're "+ str(age) +" years old? ") | |
while passb == False: | |
if checky(yn) == False and checkn(yn) == False: #If yes or no are no inputted | |
yn = input("I don't understand. Is the information correct, yes or no? ") | |
elif checky(yn): #If yes in inputted then the loop is broken | |
print("That's great!") | |
greet = False | |
passb = True | |
else: | |
print("Oh, let's start again then") #If no is inputted then yes/no loop is broken but not greetings loop | |
passb = True | |
while True: #Loop indefinitely for main part of code | |
choice = input("Hello " + name + ", what do you want to talk about?\n1. The Weather\n2. Video" | |
" Games\n3. Phones\n4. Music\n5. Sports\n6. Bye\n") #Give choices of topic | |
choice = choice.lower() #Lowercase for input | |
if choice == "1" or checkw(choice): #Check for number input or different variations of weather | |
valweather = False #Boolean variable used to validate weather input | |
# https://pypi.org/project/weather-api/ - template code | |
weather = Weather(unit=Unit.CELSIUS) #Part of weather api | |
place = input("Which place do you want to know the weather for? ") #Ask for a place to check the weather | |
while valweather == False: #Loop until a real place is inputted | |
try: | |
location = weather.lookup_by_location(place) #Part of weather api | |
condition = location.condition #Part of weather api | |
forecasts = location.forecast #Part of weather api | |
print("The weather in " + place + " is currently " + condition.text.lower()) # Displays current weather | |
for forecast in forecasts: #Part of weather api | |
print("The weather on " + forecast.date + " is " + forecast.text.lower() + ". With highs of " + forecast.high + " degrees and lows of " + forecast.low + " degrees") #Tells the forecast for the next 10 days | |
valweather = True #Break loop for a valid location input | |
except AttributeError: #Catch exceptions caused by invalid places | |
place = input("Please enter a place ") | |
except KeyError: | |
place = input("Please enter a place ") | |
elif choice == "2" or "video" in choice or "game" in choice: #Check for number input or the word "game" | |
VideoGames() #Call function containing work by Luke | |
elif choice == "3" or "phone" in choice: #Check for number input or the word "phone" | |
Phone() #Call function containing work by Sandeep | |
elif choice == "4" or "music" in choice: #Check for number input or the word "music" | |
Music() #Call function containing work by Bruno | |
elif choice == "5" or "sports" in choice: #Check for number input or the word "choice" | |
Sports(name) #Call function containing work by Joseph | |
elif choice == "6" or "bye" in choice: #Check for number input or the word "bye" | |
print("Goodbye",name,"it was nice to meet you") #Print goodbye message | |
sys.exit() #Exit program | |
else: #If the input is not a listed topic | |
print("That's not an option") |