├── Beginners ├── Code ├── FahPy.py ├── PhoneBook.py ├── Stringconcatenation.py ├── bmi.py ├── calc.py ├── calc_modified.py ├── chatbot.py ├── chocolateshop.py ├── circle.py ├── dictionary.py ├── evenodd.py ├── expensecalc.py ├── guess.py ├── hangman-new.py ├── hangman.py ├── heartshape.py ├── iterativestatements.py ├── leftpyramid.py ├── madlibs.py ├── mod.py ├── morewhile.py ├── morewhile1.py ├── multiplication.py ├── phonebook_revamped.py ├── pycontact_module.py ├── reversepyramid.py ├── rps_game.py ├── rps_game_modified.py ├── shopping.py ├── simplecalc.py ├── test.py └── volume.py ├── README.md └── WIDS_Lagos2020 └── Wids_Chatbot_Script.py /Beginners/Code: -------------------------------------------------------------------------------- 1 | 2 | #prompt a user to enter a enter a name: 3 | name = input('What is your name?: ') 4 | #Prompt a user for an adjective 5 | adjective = input('Enter an adjective: ') 6 | #prompt a user for a Plural noun 7 | noun1 = input('Enter a Plural noun: ') 8 | #Prompt a user for a noun, either a person or a thing 9 | noun2 = input('Enter any noun: ') 10 | 11 | #Print Rhyme 12 | print("Roses are " + adjective) 13 | print(noun1 + " is blue") 14 | print("I can't start my day without", noun2) 15 | -------------------------------------------------------------------------------- /Beginners/FahPy.py: -------------------------------------------------------------------------------- 1 | #convert degree celcius to fahrenheit 2 | celcius = int(input("enter a temperature in celcius: ")) 3 | fahrenheit = (celcius * 1.8) + 32 4 | print("%19f degree celcius is equal to %19f degree fahrenheit" %(celcius,fahrenheit)) 5 | -------------------------------------------------------------------------------- /Beginners/PhoneBook.py: -------------------------------------------------------------------------------- 1 | #Define a function to welcome the user and provide options on how the phonebook works 2 | def welcome(): 3 | #Create an entry variable using the input function and multiple line strings format 4 | entry = int(input("""Welcome to Py Contact Book. 5 | >>>Py Contact Book commands are: 1,2,3 or 4 <<< 6 | >>>What would you like to do?<<< 7 | 1. Display Your exiting contacts 8 | 2. Create a New contact 9 | 3. Check an entry 10 | 4. Delete an entry 11 | 5. Exit 12 | Enter your entry here(1,2,3 0r 4): """)) 13 | 14 | #Close the function 15 | return entry 16 | 17 | #Define a function Phonebook 18 | def phonebook(): 19 | #initiate an empty contact dictionary to store values 20 | contact = {} 21 | 22 | #initiate a while loop to continuously run the phonebook program 23 | while True: 24 | #call welcome function. 25 | #Set entry variable to welcome function 26 | entry = welcome() 27 | 28 | #Create conditions for decision making for any option entered by the user 29 | if entry == 1: 30 | #For first entry Check if contact dict is empty 31 | #If not empty,i.e bool(contact)==False, Print current contact list 32 | if bool(contact) != False: 33 | for k, v in contact.items(): 34 | print(k, '-->', v) 35 | #Else inform the user that the contact book is empty 36 | else: 37 | print('You have an empty phonebook! Go back to the menu to add a new contact') 38 | #Decision For the 2nd entry 39 | elif entry == 2: 40 | #Request for phone number and contact name 41 | phone_number = input('Please Enter a number: ') 42 | contact_name = input('What would you like to Save the name as? Enter in the format "FirstName,LastName".: ') 43 | 44 | #Check if the contact number already exits in Phonebook 45 | #If it does not, update current contact list in PhoneBook 46 | if phone_number not in contact.items(): 47 | contact.update({contact_name:phone_number}) 48 | #Print a success message 49 | print('Contact successfully saved') 50 | print('Your updated phonebook is Shown below: ') 51 | #Loop through Phonebook and display each contact in a separate line 52 | for k, v in contact.items(): 53 | print(k, '-->', v) 54 | #Else display a message to inform the user that contact already exits 55 | else: 56 | print('That contact already exits in your Phonebook') 57 | 58 | #Create a decision for the third entry 59 | elif entry == 3: 60 | #initiate a name variable which user wishes to view 61 | name = input('Enter the name of the contact details you wish to view: ') 62 | #Create a condition to check if the entered name is in the phonebook 63 | if name in contact: 64 | #If yes, print the required contact 65 | print('The contact is',name,':',contact[name]) 66 | 67 | #Else inform the user that the contact does not exist 68 | else: 69 | print('That contact does not exist! Return to the main menu to enter the contact') 70 | 71 | #Create a decision for entry 4 72 | elif entry == 4: 73 | #Initiate a name variable 74 | name = input('Enter the name of the contact you wish to delete: ') 75 | #check if contact exists 76 | if name in contact: 77 | #print the required contact 78 | print('The contact is',name,':',contact[name]) 79 | 80 | #Else inform the user that the contact does not exist 81 | else: 82 | print('That contact does not exist! Return to the main menu to enter the contact') 83 | 84 | 85 | #COnfirm if user wishes to delete contact 86 | confirm = input('Are you sure you wish to delete this contact? Yes/No: ') 87 | #Initiate a decision 88 | if confirm.capitalize() == 'Yes': 89 | #If yes, delete contact from Phonebook 90 | contact.pop(name,None) 91 | #Loop through Phonebook and print updated contact list 92 | for k, v in contact.items(): 93 | print('Your Updated Phonebook is shown below:') 94 | print(k, '-->', v) 95 | #ELse return to main menu 96 | else: 97 | print('Return to Main Menu') 98 | #Break program for fifth entry 99 | elif entry == 5: 100 | print('Thanks for using the Py Contact Book') 101 | break 102 | 103 | #Error Message 104 | else: 105 | print('Incorrect Entry!') 106 | 107 | 108 | #End of Program 109 | 110 | 111 | #Run Program 112 | phonebook() 113 | -------------------------------------------------------------------------------- /Beginners/Stringconcatenation.py: -------------------------------------------------------------------------------- 1 | #String concatenation 2 | 3 | #Using the Addition Operator: 4 | print('Hi!' + 'I am Diyyah') 5 | 6 | #Using variables and the addition operator 7 | h = 'Hello' 8 | w = 'World!' 9 | print(h + w) 10 | 11 | #Second Example 12 | name = input('What is your name?: ') 13 | message = 'Nice to meet you' 14 | print('Hi!' + name + '.' + message) 15 | 16 | 17 | #Using the Multiplication operator 18 | 19 | print(message * 3) 20 | -------------------------------------------------------------------------------- /Beginners/bmi.py: -------------------------------------------------------------------------------- 1 | 2 | # A simple BMI calculator with a verdict 3 | 4 | weight = float(input('Enter your weight: ')) 5 | height = float(input('Enter your height: ')) 6 | 7 | bmi = weight/(height*height) 8 | 9 | bmi = round(bmi,1) 10 | 11 | if bmi<18.5: 12 | print('You are underweighted') 13 | elif((bmi>=18.5) and (bmi<25)): 14 | print('You have a normal weight') 15 | elif((bmi>=25) and (bmi<30)): 16 | print('You are overweighted') 17 | else: 18 | print('You are Obese') 19 | -------------------------------------------------------------------------------- /Beginners/calc.py: -------------------------------------------------------------------------------- 1 | #A simple Calculator 2 | 3 | #import the mod module using any alias of choice 4 | import mod as mod 5 | 6 | # Define a function for running the calculator 7 | 8 | def calc_run(): 9 | # Define variables for two numbers using the int and input function 10 | num1 = int(input('Please enter a number: ')) 11 | num2 = int(input('Please enter another number: ')) 12 | #Define a variable for choosing operator 13 | #Use multi-line text format 14 | operator = input("""What type of mathematical operation would you like to carry out? 15 | Select an option by entering the corresponding number for the desired operation. 16 | 1. Addition 17 | 2. Subtraction 18 | 3. Multiplication 19 | 4. Division?: 20 | Ans: """) 21 | #Use conditional statements for decision making 22 | #Call out each operator from the module using the dot method 23 | 24 | if operator == '1': 25 | return mod.add(num1,num2) 26 | elif operator == '2': 27 | return mod.sub(num1,num2) 28 | elif operator == '3': 29 | return mod.mult(num1,num2) 30 | elif operator == '4': 31 | return mod.div(num1,num2) 32 | else: 33 | return "Wrong input! Kindly enter the correct option" 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Beginners/calc_modified.py: -------------------------------------------------------------------------------- 1 | #A simple Calculator 2 | 3 | #import the mod module using any alias of choice 4 | from mod import * 5 | 6 | # Define a function for running the calculator 7 | 8 | def calc_run(): 9 | # Define variables for two numbers using the int and input function 10 | num1 = int(input('Please enter a number: ')) 11 | num2 = int(input('Please enter another number: ')) 12 | #Define a variable for choosing operator 13 | #Use multi-line text format 14 | operator = input("""What type of mathematical operation would you like to carry out? 15 | Select an option by entering the corresponding number for the desired operation. 16 | 1. Addition 17 | 2. Subtraction 18 | 3. Multiplication 19 | 4. Division?: 20 | Ans: """) 21 | #Use conditional statements for decision making 22 | #Call out each operator from the module using the dot method 23 | 24 | if operator == '1': 25 | return add(num1,num2) 26 | elif operator == '2': 27 | return sub(num1,num2) 28 | elif operator == '3': 29 | return mult(num1,num2) 30 | elif operator == '4': 31 | return div(num1,num2) 32 | else: 33 | return "Wrong input! Kindly enter the correct option" 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Beginners/chatbot.py: -------------------------------------------------------------------------------- 1 | # Initiate a Welcome message and an introduction 2 | 3 | print('Hey there!. I am Annie') 4 | name = input('What is your name?: ') 5 | print('Hi!', name, ', Nice to meet you') 6 | 7 | #1st conversation 8 | feelings = input("How are you today?: ") 9 | responses = ['Okay',"I'm fine","I'm doing great", "I'm ok","I'm good",'Good','Awesome', 'Great','Superb'] 10 | if feelings in responses: 11 | print("I'm so Glad to hear that!") 12 | else: 13 | print('Oh dear!') 14 | print('Why do you feel', feelings) 15 | reason = input('Please tell me: ') 16 | print('I understand.It is absolutely ok to feel that way sometimes.Thanks for sharing') 17 | 18 | #2nd Conversation 19 | #Ask for user's age 20 | userAge = int(input('How old are you?: ')) 21 | if userAge >= 18 and userAge <= 24: 22 | print('Cool!You are a Young Adult') 23 | elif userAge >= 25 and userAge <= 44: 24 | print('Whoa!You are all grown up!') 25 | elif userAge > 45: 26 | print('Great!You seem like an elderly person') 27 | else: 28 | print('It feels so nice to be a teenager') 29 | 30 | #Conversation about continent 31 | world = ('Africa', 'Antractica','Asia', 'Australia', 'Europe','North-America', 'South-America') 32 | continent = input('What continent are you from?: ') 33 | if continent in world and continent == 'Africa': 34 | print("That's cool! I have heard a lot about Africa and its richness for culture and nature parks") 35 | print('I sure would love to visit someday') 36 | elif continent in world and continent == 'Asia': 37 | print('Nice! Asians have a very unique culture. Beautiful culture, beautiful places, beautiful people.') 38 | elif continent in world and continent == 'Europe': 39 | print('Amazing!Europe is known for its unique building structures') 40 | elif continent in world and continent == 'Antractica': 41 | print('I heard the weather tends to get extreme over there and very few people live there. So glad to be chatting with a native') 42 | elif continent in world and continent == 'Australia': 43 | print('I would definitely love to visit sometime.I have a few friends from over there and they also tell me a lot of interesting stories') 44 | else: 45 | print('I have been to North-America a couple of times. I also love watching mexican movies. I think America is generally a rich continent') 46 | 47 | #Conversation on Year 48 | year = int(input('I am not very good at dates. What year is it?: ')) 49 | if year == 2020: 50 | print('You are very smart! It is the year of the global pandemic') 51 | print('Do stay safe at all times!') 52 | else: 53 | print('You are a genius! I have troubles remembering dates') 54 | 55 | #Ending the conversation 56 | print('I absolutely loved chatting with you today. Hope to talk to you some other time') 57 | print('Bye', name, '!You have quite an interesting personality. Do Take care!') 58 | -------------------------------------------------------------------------------- /Beginners/chocolateshop.py: -------------------------------------------------------------------------------- 1 | #Create a welcome message 2 | print("Hi there, Welcome to Chloe's Chocolate Shop!") 3 | 4 | #Ask User for Name and Print a message 5 | name = input('What is your name?: ') 6 | print("Hi " + name + "! What would you like to eat Order?") 7 | print('We have some very tasty and irresistible Chocolates.Take a look at our menu below and make your order') 8 | 9 | #Create a Menu 10 | menu = input("\n(a) Caramel Chocolate - NGN999.99 \n(b) Dark Chocolate with Hazelnut - NGN1299.99 \n(c) KitKat Medium Size- NGN399.99 \n(d) Toberone White Chocolate(Large)- NGN1499.99 \n(e) I can't find my Favorite Chocolate: ") 11 | 12 | #Add a note 13 | 14 | note1 = ("\n Thank you for Shopping with us Today. We hope you love your order.Your order is being processed........") 15 | note2 = ("\n You'll be redirected to a payment site soon......") 16 | 17 | #Create Conditionals 18 | if(menu.lower() == 'a'): 19 | print('Great Choice!!',note1 ,note2, sep='\n') 20 | elif(menu.lower() == 'b'): 21 | print('You Have such great Taste!!', note1, note2, sep='\n') 22 | elif(menu.lower() == 'c'): 23 | print('Delicious!!', note1, note2,sep='\n') 24 | elif(menu.lower() =='d'): 25 | print('Hmmm!Yummy!', note1, note2,sep='\n') 26 | else: 27 | print("Can't see your Favorite Chocolate? No Worries!!contact us now through our live chat, We've got you covered") 28 | 29 | #Final Goodbye message 30 | print('Goodbye! We hope to see you again') 31 | -------------------------------------------------------------------------------- /Beginners/circle.py: -------------------------------------------------------------------------------- 1 | #area of a circle 2 | pi = 3.142 3 | r = int(input('enter the radius of a circle')) 4 | area = pi * r * r 5 | print('area of a circle',area) 6 | -------------------------------------------------------------------------------- /Beginners/dictionary.py: -------------------------------------------------------------------------------- 1 | #A dictionary data structure 2 | myDetails = {'FirstName' : 'Mark', 3 | 'LastName' : 'Anthony', 4 | 'Occupation' : 'Student', 5 | 'Age' : 27, 6 | 'Weight': 56.5, 7 | 'Height' : 165.2, 8 | 'Excited' : True} 9 | -------------------------------------------------------------------------------- /Beginners/evenodd.py: -------------------------------------------------------------------------------- 1 | num = int(input('Please enter a number:')) 2 | if(num % 2 == 0): 3 | print(num, 'is an even number') 4 | else: 5 | print(num, 'is a odd number') 6 | -------------------------------------------------------------------------------- /Beginners/expensecalc.py: -------------------------------------------------------------------------------- 1 | 2 | # A simple Expense Calculator 3 | weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday'] 4 | weekend = ['Saturday', 'Sunday'] 5 | day = input('What day is it today? ') 6 | bank_balance = int(input("What's your account balance: ")) 7 | if(day in weekend) and (bank_balance > 20000): 8 | print("Go for shopping") 9 | elif(day in weekday) or (bank_balance < 20000): 10 | print("You can't go shopping yet") 11 | else: 12 | print("it's a working day") 13 | -------------------------------------------------------------------------------- /Beginners/guess.py: -------------------------------------------------------------------------------- 1 | #Building a Guessing Game 2 | 3 | #create a secret word 4 | secret_word = "Python" 5 | 6 | #Create a Guess variable using the input statement 7 | 8 | guess = input('Guess what the Secret Word is: ') 9 | 10 | #Create a condition using the While keyword 11 | 12 | while guess != secret_word: 13 | print('Oops!Wrong guess.Try again') 14 | guess = input('Try a new Guess!: ') 15 | print('Yaay! You guessed right.Great job') 16 | ##guess = "" 17 | ##guess_count = 0 18 | ##guess_limit = 3 19 | ##out_of_guesses = False 20 | ## 21 | ##while guess != secret_word and not(out_of_guesses): 22 | ## if guess_count < guess_limit: 23 | ## guess = input("Enter a guess: ") 24 | ## guess_count += 1 25 | ## else: 26 | ## out_of_guesses = True 27 | ## 28 | ##if out_of_guesses: 29 | ## print("You Lose!") 30 | ##else: 31 | ## print("You Win!") 32 | -------------------------------------------------------------------------------- /Beginners/hangman-new.py: -------------------------------------------------------------------------------- 1 | #import the built-in python modules: Json, urllib and random 2 | import json 3 | import random 4 | import urllib.request 5 | 6 | #Define the following variables to request for a random word from the github repository 7 | url = urllib.request.urlopen("https://raw.githubusercontent.com/sindresorhus/mnemonic-words/master/words.json") 8 | words = json.loads(url.read()) 9 | 10 | #Define a function welcome 11 | def welcome(): 12 | 13 | #Define a name variable 14 | name = input(""" 15 | ================================================================ 16 | > Welcome to the Hangman Game! Please Enter your preferred game name: < 17 | """).capitalize() 18 | 19 | #Use a decision making process to accept only alphabets as name 20 | if name.isalpha() == True: 21 | print(""">> Hi!""",name,"""Glad to have you here! <<< 22 | You will be playing against the computer today. 23 | The computer will randomly choose a word and you will try to guess what the word is. 24 | You can always invite your friends for a fun time together 25 | ========================================================== 26 | Good Luck! Have fun playing""") 27 | 28 | 29 | else: 30 | print('Please enter your name using letter only') 31 | name = input('Enter a game name here: ') 32 | print('Hi!',name,'Please go through the rules of the game below') 33 | 34 | 35 | #Define another function play_again 36 | #Add a docstrings 37 | def play_again(): 38 | 39 | """ This function asks user/player if he/she wishes to replay the hangman game """ 40 | response = input("Would you like to play again? yes/no. Enter 'Y' for Yes or 'N' for No: ").lower() 41 | reply = ('y','n') 42 | 43 | 44 | #Create a decision making process 45 | if response not in reply: 46 | print('Invalid Entry! Please check that you entered the correct input: ') 47 | response = input("Please enter the correct input here. Either yes/no. Enter 'Y' for Yes or 'N' for No: ").lower() 48 | 49 | else: 50 | if response == 'y': 51 | game_run() 52 | 53 | elif response == 'n': 54 | print('Hope you had fun playing the game. See you next time') 55 | 56 | 57 | #Define another function get_word for generating random words for the user to guess. 58 | #Add a docstrings 59 | def get_word(): 60 | """ This function generates the word the user will attempt guessing. 61 | Using the Json and Urllib library, this word will be randomly generated from the defined link. 62 | So in a way, this function acts as an Automatic random word generator for the Hangman game""" 63 | 64 | return random.choice(words).lower() 65 | 66 | #Define another function game_run() 67 | #Add a docstring if desired 68 | 69 | def game_run(): 70 | #call the welcome function to get the game running 71 | welcome() 72 | 73 | #Define a variable alpahabet 74 | alphabet = ('abcdefghijklmnopqrstuvwxyz') 75 | 76 | #Set guess word to get_word function for a random word to be generated 77 | word = get_word() 78 | 79 | #Initiate an empty list for guessed letter 80 | letters_guessed = [] 81 | 82 | #Initiate a tries variable for number of tries by the user 83 | tries = 7 84 | 85 | #Set inital guess to false 86 | guessed = False 87 | 88 | #Print an empty line 89 | print() 90 | 91 | #Print a guess hint for the user for number of letters contained in the word 92 | 93 | print('The word contains', len(word), 'letters.') 94 | print(len(word) * '_') 95 | 96 | #Initate a while loop and create decisions, taking into consideration if the user decides to enter just a single letter or the full word 97 | #Also a create decisions for if user inputs a wrong entry and if user inputs letters and it is not equal to the total number of letters in the word to guess 98 | #Deduct tries each user fails to guess incorrectly 99 | while not guessed and tries > 0: 100 | print('You have ' + str(tries) + ' tries') 101 | guess = input('Guess a letter in the word or enter the full word.').lower() 102 | #user inputs a letter 103 | if len(guess) == 1: 104 | if guess not in alphabet: 105 | print('You are yet to enter a letter. Check your entry, make sure you enter an alphabet not a number') 106 | elif guess in letters_guessed: 107 | print('You have already guessed that letter before.Try again!') 108 | elif guess not in word: 109 | print('Sorry, that letter is not part of the word.') 110 | letters_guessed.append(guess) 111 | tries -=1 112 | elif guess in word: 113 | print('Great! That letter exists in the word!Keep Going!!') 114 | letters_guessed.append(guess) 115 | else: 116 | print('Check your entry!You might have entered the wrong entry') 117 | 118 | #user inputs the full word 119 | elif len(guess) == len(word): 120 | if guess == word: 121 | print('Great Job! You guessed the word correctly!') 122 | print(The word is': word) 123 | guessed = True 124 | else: 125 | print('Sorry, that\'s not the word!') 126 | print('The correct word was: ', word) 127 | tries -= 1 128 | 129 | #user inputs letters and it is not equal to the total number of letters in the word to guess. 130 | else: 131 | print('The length of your guess is not the same as the length of the correct word.') 132 | tries -=1 133 | 134 | status = '' 135 | if guessed == False: 136 | for letter in word: 137 | if letter in letters_guessed: 138 | status += letter 139 | else: 140 | status += '_' 141 | #Initiate the display hangman image here 142 | #The function for is defined below 143 | print(hangman(tries)) 144 | print(status) 145 | 146 | 147 | if status == word: 148 | print('Great Job! You guessed the word correctly!') 149 | guessed = True 150 | elif tries == 0: 151 | print("Opps! You ran out of guesses and you couldn't guessed the word.") 152 | print('The correct word was: ', word) 153 | 154 | #Initiate play_again function if user wishes to continue 155 | play_again() 156 | 157 | 158 | #Define a new function for the hangman image 159 | #Use the list Data structure and intuitively draw the hangman image. 160 | #Use indexing and multiple line string format to draw image progression at each position such that the images will be displayed accordingly for a given number of tries left 161 | 162 | def hangman(tries): 163 | stages = [ """ 164 | -------- 165 | | | 166 | | O 167 | | \|/ 168 | | | 169 | | / \ 170 | - 171 | """, 172 | """ 173 | -------- 174 | | | 175 | | O 176 | | \|/ 177 | | | 178 | | / 179 | - 180 | """, 181 | """ 182 | -------- 183 | | | 184 | | O 185 | | \|/ 186 | | | 187 | | 188 | - 189 | """, 190 | """ 191 | -------- 192 | | | 193 | | O 194 | | \| 195 | | | 196 | | 197 | - 198 | """, 199 | """ 200 | -------- 201 | | | 202 | | O 203 | | | 204 | | | 205 | | 206 | - 207 | """, 208 | """ 209 | -------- 210 | | | 211 | | O 212 | | 213 | | 214 | | 215 | - 216 | """, 217 | """ 218 | -------- 219 | | | 220 | | 221 | | 222 | | 223 | | 224 | - 225 | """ 226 | ] 227 | return stages[tries] 228 | #Full program run 229 | game_run() 230 | -------------------------------------------------------------------------------- /Beginners/hangman.py: -------------------------------------------------------------------------------- 1 | #import the random module 2 | import random 3 | 4 | 5 | #Define a function welcome 6 | def welcome(): 7 | 8 | #Define a name variable 9 | name = input(""" 10 | ================================================================ 11 | > Welcome to the Hangman Game! Please Enter your preferred game name: < 12 | """).capitalize() 13 | 14 | #Use a decision making process to accept only alphabets as name 15 | if name.isalpha() == True: 16 | print(""">> Hi!""",name,"""Glad to have you here! <<< 17 | You will be playing against the computer today. 18 | The computer will randomly choose a word and you will try to guess what the word is. 19 | You can always invite your friends for a fun time together 20 | ========================================================== 21 | Good Luck! Have fun playing""") 22 | 23 | 24 | else: 25 | print('Please enter your name using letter only') 26 | name = input('Enter a game name here: ') 27 | print('Hi!',name,'Please go through the rules of the game below') 28 | 29 | 30 | #Define another function play_again 31 | #Add a docstrings 32 | def play_again(): 33 | 34 | """ This function asks user/player if he/she wishes to replay the hangman game """ 35 | response = input("Would you like to play again? yes/no. Enter 'Y' for Yes or 'N' for No").lower() 36 | 37 | #Create a decision making process 38 | if response == 'y': 39 | game_run() 40 | else: 41 | print('Hope you had fun playing the game. See you next time') 42 | 43 | 44 | #Define another function get_word for generating random words for the user to guess. 45 | #Add a docstrings 46 | def get_word(): 47 | """ This function generates the word the user will attempt guessing""" 48 | words = ['Python', 'cool', 'Weather', 'exciting', 'happy'] 49 | return random.choice(words).lower() 50 | 51 | #Define another function game_run() 52 | #Add a docstring if desired 53 | 54 | def game_run(): 55 | #call the welcome function to get the game running 56 | welcome() 57 | 58 | #Define a variable alpahabet 59 | alphabet = ('abcdefghijklmnopqrstuvwxyz') 60 | 61 | #Set guess word to get_word function for a random word to be generated 62 | word = get_word() 63 | 64 | #Initiate an empty list for guessed letter 65 | letters_guessed = [] 66 | 67 | #Initiate a tries variable for number of tries by the user 68 | tries = 7 69 | 70 | #Set inital guess to false 71 | guessed = False 72 | 73 | #Print an empty line 74 | print() 75 | 76 | #Print a guess hint for the user for number of letters contained in the word 77 | 78 | print('The word contains', len(word), 'letters.') 79 | print(len(word) * '_') 80 | 81 | #Initate a while loop and create decisions, taking into consideration if the user decides to enter just a single letter or the full word 82 | #Also a create decisions for if user inputs a wrong entry and if user inputs letters and it is not equal to the total number of letters in the word to guess 83 | #Deduct tries each user fails to guess incorrectly 84 | while guessed == False and tries > 0: 85 | print('You have ' + str(tries) + ' tries') 86 | guess = input('Guess a letter in the word or enter the full word.').lower() 87 | #user inputs a letter 88 | if len(guess) == 1: 89 | if guess not in alphabet: 90 | print('You are yet to enter a letter. Check your entry, make sure you enter an alphabet not a number') 91 | elif guess in letters_guessed: 92 | print('You have already guessed that letter before.Try again!') 93 | elif guess not in word: 94 | print('Sorry, that letter is not part of the word :(') 95 | letters_guessed.append(guess) 96 | tries -=1 97 | elif guess in word: 98 | print('Great! That letter exists in the word!') 99 | letters_guessed.append(guess) 100 | else: 101 | print('Check your entry!You might have entered the wrong entry') 102 | 103 | #user inputs the full word 104 | elif len(guess) == len(word): 105 | if guess == word: 106 | print('Great Job! You guessed the word correctly!') 107 | guessed = True 108 | else: 109 | print('Sorry, that was not the word we were looking for :(') 110 | tries -= 1 111 | 112 | #user inputs letters and it is not equal to the total number of letters in the word to guess. 113 | else: 114 | print('The length of your guess is not the same as the length of the correct word.') 115 | tries -=1 116 | 117 | status = '' 118 | if guessed == False: 119 | for letter in word: 120 | if letter in letters_guessed: 121 | status += letter 122 | else: 123 | status += '_' 124 | print(status) 125 | 126 | 127 | if status == word: 128 | print('Great Job! You guessed the word correctly!') 129 | guessed = True 130 | elif tries == 0: 131 | print("Opps! You ran out of guesses and you couldn't guessed the word.") 132 | 133 | #Initiate play_again function if user wishes to continue 134 | play_again() 135 | 136 | #Full program run 137 | game_run() 138 | -------------------------------------------------------------------------------- /Beginners/heartshape.py: -------------------------------------------------------------------------------- 1 | #Printing Heart shape 2 | #Ist for loop with 6 rows 3 | for i in range(6): 4 | #2nd for loop for columns 5 | for j in range(7): 6 | #initate if condition using logical and, or, to define where stars will be printed 7 | if(i==0 and j%3!=0) or (i==1 and j%3==0) or (i-j==2) or (i+j==8): 8 | print("*", end="") 9 | #initiate else statement 10 | else: 11 | print(end=" ") 12 | print() 13 | -------------------------------------------------------------------------------- /Beginners/iterativestatements.py: -------------------------------------------------------------------------------- 1 | #WHile Loop 2 | list = ['running','sleeping', 'eating'] 3 | hobbies = input('Enter a hobby: ') 4 | hobbies = hobbies.lower() 5 | while hobbies in list: 6 | print('Great choice') 7 | else: 8 | print('Tell me more') 9 | 10 | #For Loop 11 | list = ['running','sleeping', 'eating'] 12 | hobbies = input('Enter a hobby: ') 13 | hobbies = hobbies.lower() 14 | for hobbies in list: 15 | print('Great choice') 16 | else: 17 | print('Tell me more') 18 | -------------------------------------------------------------------------------- /Beginners/leftpyramid.py: -------------------------------------------------------------------------------- 1 | #Creating a Left Sided Pyramid shape in Python using a nested loop 2 | for pattern in range(1,10): 3 | for stars in range(pattern): 4 | print('*') 5 | print("") 6 | -------------------------------------------------------------------------------- /Beginners/madlibs.py: -------------------------------------------------------------------------------- 1 | #prompt a user to enter a enter a name: 2 | name = input('What is your name?: ') 3 | #Prompt a user for an adjective 4 | adjective = input('Enter an adjective: ') 5 | #prompt a user for a Plural noun 6 | noun1 = input('Enter a Plural noun: ') 7 | #Prompt a user for a noun, either a person or a thing 8 | noun2 = input('Enter any noun: ') 9 | 10 | #Print Rhyme 11 | print("Roses are " + adjective) 12 | print(noun1 + " is blue") 13 | print("I can't start my day without", noun2) 14 | -------------------------------------------------------------------------------- /Beginners/mod.py: -------------------------------------------------------------------------------- 1 | #Calculator module 2 | #Function for Addition 3 | def add(num1,num2): 4 | return num1 + num2 5 | 6 | #Function for subtraction 7 | def sub(num1,num2): 8 | return num1 - num2 9 | 10 | #Function for Mutiplication 11 | def mult(num1,num2): 12 | return num1 * num2 13 | 14 | #Function for Division 15 | def div(num1,num2): 16 | return num1 / num2 17 | -------------------------------------------------------------------------------- /Beginners/morewhile.py: -------------------------------------------------------------------------------- 1 | #creating an infinite loop 2 | #using the while loop 3 | 4 | mood = input('Are you hungry?: ') 5 | while mood == ‘Yes’: 6 | print('I am still Hungry') 7 | 8 | #So the while loop can be stopped using ctrl + c on the keyboard. 9 | #This is called a keyboard interrupt. 10 | #It is used for stopping an infinite loop such as the while loop. 11 | 12 | 13 | -------------------------------------------------------------------------------- /Beginners/morewhile1.py: -------------------------------------------------------------------------------- 1 | #Creating a simple step Counter 2 | count = 0 3 | while (count<20000): 4 | print(count) 5 | count+=1 6 | -------------------------------------------------------------------------------- /Beginners/multiplication.py: -------------------------------------------------------------------------------- 1 | ##Define a variable num, using the int and input function 2 | ##num = int(input('Which number would you like to use for your multiplication table: ')) 3 | ## 4 | ##Create an iterative condition using the for loop and the range function 5 | ##Set a start point at 1 and end point at 13 6 | ##This is so that the multiplication table runs and stops at 12 7 | ## 8 | ##for i in range(num): 9 | ## for j in range(i): 10 | ## print(num*i, end="") 11 | ## print("\r") 12 | 13 | #Creating a pattern in Python with a nested loop 14 | for pattern in range(1,10): 15 | for stars in range(pattern): 16 | print('*',end="") 17 | print("") 18 | -------------------------------------------------------------------------------- /Beginners/phonebook_revamped.py: -------------------------------------------------------------------------------- 1 | #Import the pycontact module 2 | 3 | from pycontact_module import * 4 | 5 | 6 | #Define a function to initiate the phonebook program 7 | #Call the menu function from pycontact 8 | def Phonebook(): 9 | 10 | #call menu function. 11 | contacts={} 12 | menu() 13 | 14 | #Call the Phonebook function to run the program 15 | Phonebook() 16 | -------------------------------------------------------------------------------- /Beginners/pycontact_module.py: -------------------------------------------------------------------------------- 1 | #Define an empty dictionary to store contact information as a global variable 2 | contacts={} 3 | 4 | #Define a function 'menu' to welcome the user and provide options on how the phonebook works 5 | def menu(): 6 | #Use a try except block inside the function to take care of possible wrong responses by the user 7 | #Define a variable 'entry' for user options 8 | try: 9 | entry =int(input("""Welcome to Py Contact Book. 10 | >>>Py Contact Book commands are: 1,2,3 or 4 <<< 11 | >>>What would you like to do?<<< 12 | 1. Display Your existing contacts 13 | 2. Create a New contact 14 | 3. Check an entry 15 | 4. Delete an entry 16 | 5. Exit 17 | Enter (1,2,3,4) or enter [5] to exit: """)) 18 | 19 | #For the except block, use a valueerror exception 20 | #in the exception block re-define the variable 'entry', letting the users aware of what type of inputs should be in there 21 | except ValueError: 22 | entry=int(input('Wrong entry! Enter a number [1-5]')) 23 | #Include decision making processes using the control flow statements 24 | #This flow control statement will call other functions defined beneath 25 | if entry ==1: 26 | #Function for displaying contact 27 | DisplayAll() 28 | elif entry==2: 29 | #Function for adding contact details 30 | AddContact() 31 | elif entry==3: 32 | #Function for viewing contact 33 | ViewContact() 34 | elif entry ==4: 35 | #Function for deleting contact 36 | DelContact() 37 | else: 38 | #Closing statement 39 | print('\n\b Thanks for using the Py Contact Book') 40 | 41 | #Define another function display query with required argument query, as disp(query) 42 | #Set up a decision-making process using control flow statements 43 | #Initiate two new functions 'DisplayAll' and 'Addcontact', to be defined below. 44 | def disp(query): 45 | #Set up a decision making process using control flow statements 46 | if query in contacts.keys(): 47 | print(contacts[query]) 48 | dlt=input('Want to delete this contact ?[Y/N]').lower() 49 | if dlt=='y': 50 | DelContact() 51 | else: 52 | DisplayAll() 53 | else: 54 | pi=input('Error 404, contact not found. Want to add this contact? [Y/N]').lower() 55 | if pi=='y': 56 | AddContact() 57 | else: 58 | pass 59 | #Define a new function 'DisplayAll' 60 | #Include decision making using control statements 61 | #Call the menu function defined earlier at the end of this function 62 | def DisplayAll(): 63 | if len(contacts) >= 1: 64 | print('your contacts are:\n','+'*30) 65 | for contact, num in contacts.items(): 66 | print(contact, '-----', num) 67 | else: 68 | print('You have an empty Contact List') 69 | opt=input('Want to Add contacts? Y/N :') 70 | if opt.capitalize()=='Y': 71 | AddContact() 72 | else: 73 | pass 74 | menu() 75 | 76 | #Define a new function AddContact 77 | #Use the try-except block here too 78 | #Include conditions for decision making 79 | #Call the displayall function 80 | #Call the disp(query) function 81 | def AddContact(): 82 | print('You can add a new entry here') 83 | name=str(input('Enter Name :').capitalize()) 84 | try: 85 | num = int(input('Enter Num :')) 86 | except ValueError: 87 | input('invalid value entered') 88 | num = 0 89 | '''return num''' 90 | if name not in contacts.keys(): 91 | contacts[name]=num 92 | print('You have successfully added ', contacts[name], 'to your contacts') 93 | DisplayAll() 94 | else: 95 | print('This Contact already exists in phonebook') 96 | disp(name) 97 | 98 | #Define a new function 'ViewContact' 99 | #Using decision making here also 100 | #Call the disp(query) function 101 | def ViewContact(): 102 | query=input('Enter the name or number you want to view: ') 103 | if type(query)==str: 104 | query = query.capitalize() 105 | disp(query) 106 | elif type(query)==int: 107 | print(contacts.values()) 108 | 109 | #Final function for the module 110 | #Define a function 'DelContact' 111 | #Initiate a decision making 112 | #Call the 'DisplayAll' function 113 | def DelContact(): 114 | name=str(input('Enter name of the contact you wish to delete').capitalize()) 115 | confirm = input('Are you sure you wish to delete this contact? Y/N: ') 116 | #Initiate a decision 117 | if confirm.upper() == 'Y': 118 | #If yes, delete contact from Phonebook 119 | contacts.pop(name) 120 | else: 121 | pass 122 | DisplayAll() 123 | 124 | -------------------------------------------------------------------------------- /Beginners/reversepyramid.py: -------------------------------------------------------------------------------- 1 | #Reverse Pyramid Shape 2 | for i in range(10, 0,-1): 3 | for j in range(i): 4 | print("* ", end="") 5 | print() 6 | -------------------------------------------------------------------------------- /Beginners/rps_game.py: -------------------------------------------------------------------------------- 1 | #import the random module 2 | import random 3 | 4 | #Initiate a welcome message 5 | 6 | print(""">>> Welcome to the 'Rock,Paper, Scissors game'.Glad to have you here! <<< 7 | You will be playing against the computer today. 8 | You can always invite your friends for a fun time together""") 9 | 10 | #Create a name variable for the player/user 11 | name = input('Please enter your prefered game name: ') 12 | 13 | #print a greeting message for the user/player with game instruction 14 | 15 | print('Hi,',name,'! Make a choice below to start the game') 16 | 17 | #Create a choice variable using the Tuple data structure 18 | 19 | choices = ('Rock', 'Paper', 'Scissors') 20 | 21 | #Initiate game sequence using the Flow control statements for decision making 22 | #Start with a while loop 23 | while True: 24 | #Create a player variable, for player's choice 25 | player = input("What's your choice? Rock, Paper or Scissors: ").capitalize() 26 | 27 | #Check for correct entry 28 | if player not in choices: 29 | print('Oops!Wrong Entry.Check Your Spelling') 30 | else: 31 | print(name, "-You picked-->", player) 32 | 33 | #Initiate computer's choice 34 | computer = random.choice(choices) 35 | 36 | #Print Computer's choice 37 | print("The Computer's Choice is:",computer) 38 | 39 | #Create game decisions using conditional statements 40 | 41 | if player == computer: 42 | print("Opps!It's a Tie!Try again!") 43 | elif (player == 'Rock' and computer == 'Paper') or (player == 'Paper' and computer == 'Scissors') or (player == 'Scissors' and computer == 'Rock'): 44 | print(name,"Sorry You lose!As per the rules of the game", computer, 'beats', player) 45 | else: 46 | print("Yaay!",name, "wins!",player, "beats", computer) 47 | 48 | 49 | -------------------------------------------------------------------------------- /Beginners/rps_game_modified.py: -------------------------------------------------------------------------------- 1 | #import the random module 2 | import random 3 | 4 | #Initiate a welcome message 5 | 6 | print(""">>> Welcome to the 'Rock,Paper, Scissors game'.Glad to have you here! <<< 7 | You will be playing against the computer today. 8 | You can always invite your friends for a fun time together""") 9 | 10 | #Create a name variable for the player/user 11 | name = input('Please enter your prefered game name: ') 12 | 13 | #print a greeting message for the user/player with game instruction 14 | 15 | print('Hi,',name,'! Make a choice below to start the game') 16 | 17 | #Create a choice variable using the Tuple data structure 18 | 19 | choices = ('Rock', 'Paper', 'Scissors') 20 | 21 | #initiate a score point 22 | player_score = 0 23 | computer_score = 0 24 | 25 | #Initiate game sequence using the Flow control statements for decision making 26 | #Start with a while loop 27 | while True: 28 | #Create a player variable, for player's choice 29 | player = input("What's your choice? Rock, Paper or Scissors: ").capitalize() 30 | 31 | #Check for correct entry 32 | if player not in choices: 33 | print('Oops!Wrong Entry.Check Your Spelling') 34 | else: 35 | print(name, "-You picked-->", player) 36 | 37 | #Initiate computer's choice 38 | computer = random.choice(choices) 39 | 40 | #Print Computer's choice 41 | print("The Computer's Choice is:",computer) 42 | 43 | #Create game decisions using conditional statements 44 | 45 | if player == computer: 46 | print("Opps!It's a Tie!Try again!") 47 | elif (player == 'Rock' and computer == 'Paper') or (player == 'Paper' and computer == 'Scissors') or (player == 'Scissors' and computer == 'Rock'): 48 | print(name,"Sorry You lose!As per the rules of the game", computer, 'beats', player) 49 | computer_score += 1 50 | print(name, ',Your score is:',player_score) 51 | print("The computer's score is:",computer_score) 52 | else: 53 | print("Yaay!",name, "wins!",player, "beats", computer) 54 | player_score += 1 55 | print(name, ',Your score is:',player_score) 56 | print("The computer's score is:",computer_score) 57 | 58 | 59 | -------------------------------------------------------------------------------- /Beginners/shopping.py: -------------------------------------------------------------------------------- 1 | #Create a welcome message 2 | print("Bonjour! Welcome to Chloe's Chocolate Shop!") 3 | 4 | #Ask User for Name and Print a message 5 | name = input('What is your name?: ') 6 | print("Hi " + name + "! What would you like to eat Order?") 7 | print('We have some very tasty and irresistible Chocolates.Take a look at our menu below and make your order') 8 | 9 | #Print an empty line 10 | print() 11 | print('For each item, we have the price and the quantity in stock attached') 12 | 13 | #Create a Menu using dictionary 14 | menu = {1: ('Caramel Chocolate -> Qty:50', 999.99), 15 | 2: ('Dark Chocolate with Hazelnut -> Qty:120', 1299.99), 16 | 3: ('KitKat Medium Size -> Qty:80',399.99), 17 | 4: ('Toberone White Chocolate(Large)-> Qty:150',1499.99), 18 | 5: 'Option not listed'} 19 | 20 | #Iterate through the menu dictionary to show each item, the price and the quantity 21 | for k, v in menu.items(): 22 | print (k, '-->', v) 23 | 24 | #print an empty line 25 | print() 26 | 27 | #Create an empty list for shopping cart 28 | shopping_cart = [] 29 | 30 | #Initiate order 31 | items = (""" 32 | Keynames for Shopping 33 | Caramel 34 | Dark Chocolate 35 | Kitkat 36 | Toberone 37 | """) 38 | print(items) 39 | print() 40 | order = input('To make an order, enter the name of the Item using the keyname as listed above: ') 41 | 42 | #Initiate While loop to check if order in listed item 43 | while order.capitalize() in items: 44 | #append order to empty shopping cart list 45 | shopping_cart.append(order) 46 | #Ask user if they wish to add more items 47 | cart = input('Want to add more items to your basket?Enter Y/N: ') 48 | #Initiate a while loop to validate user's response 49 | while cart.lower() == 'y': 50 | order = input('Enter the name of the item using the keyname: ') 51 | shopping_cart.append(order) 52 | cart = input('Want to add more items to your basket?Enter Y/N: ') 53 | #Close shopping with an else statement 54 | else: 55 | print('We organized your shopping list for you, Just in order as you selected the items.View below before proceeding to payment') 56 | print(shopping_cart) 57 | print("You'll be redirected to a payment site soon......") 58 | print('Thank you for shopping with us ',name,' We look forward to seeing you again') 59 | break #break loop to exit 60 | -------------------------------------------------------------------------------- /Beginners/simplecalc.py: -------------------------------------------------------------------------------- 1 | #Building a Simple Calculator 2 | #Use the input func to ask a user for an input 3 | 4 | first_num = float(input('Please Enter a number: ' )) 5 | second_num = float(input('Please Enter another number:' )) 6 | 7 | #Addition 8 | print(first_num + second_num) 9 | 10 | #Subtraction 11 | print(first_num - second_num) 12 | 13 | #Multiplication 14 | print(first_num * second_num) 15 | 16 | #Exponential 17 | print(first_num ** second_num) 18 | 19 | #Division 20 | print(first_num / second_num) 21 | 22 | #Floor Division 23 | print(first_num // second_num) 24 | 25 | #Modulus Division 26 | print(first_num % second_num) 27 | -------------------------------------------------------------------------------- /Beginners/test.py: -------------------------------------------------------------------------------- 1 | def add(x,y=5): 2 | return x + y 3 | -------------------------------------------------------------------------------- /Beginners/volume.py: -------------------------------------------------------------------------------- 1 | import math 2 | r = int(input('Enter a value')) 3 | pi = math.pi 4 | volume = (4/3) * pi * (r**3) 5 | print(volume) 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-Projects 2 | 3 | This is the repository for my blog series on "Learning Python Through Projects". The repository contains all codes used in the article, fully commented for an understanding of what each line of code does. 4 | 5 | These projects are beginners-focused and aimed at building logical reasoning before building, so concepts learned can be applied to other projects/problems encountered. 6 | 7 | You can read the related articles here: 8 | 1. [BUILDING A SIMPLE MADLIB WITH PYTHON](https://mardiyyah.medium.com/building-a-simple-madlib-with-python-pythonbeginnerseries-cbf4fe799eaf) 9 | 2. [Building a Simple Calculator](https://mardiyyah.medium.com/learning-python-through-projects-series-2-building-a-simple-calculator-pythonbeginnerseries-91441d7eeb98) 10 | 3. [A GUESSING GAME](https://mardiyyah.medium.com/a-guessing-game-series-3-learning-python-through-projects-pythonbeginnerseries-74b60a1e1798) 11 | 4. [Annie the Chatbot](https://mardiyyah.medium.com/annie-the-chatbot-learningpythonthroughproject-series-4-a178eb5a76eb) 12 | 5. [CREATING A MENU](https://mardiyyah.medium.com/creating-a-menu-an-online-chocolate-store-learningpythonthroughprojects-series-5-983e1519eb65) 13 | 6. [CHOCOLATE STORE UPDATED](https://mardiyyah.medium.com/chocolate-store-updated-learnpythonthroughproject-series-6-eac86e89f895) 14 | 7. [Creating Patterns in Python](https://mardiyyah.medium.com/creating-patterns-in-python-learnpythonthroughprojects-series-7-3e78db1b3a04) 15 | 8. [Rock, Paper, and Scissors](https://mardiyyah.medium.com/rock-paper-and-scissors-series-8-learnpythonthroughprojects-e5cb1b9ba730) 16 | 9. [A Simple Calculator: Revisted](https://mardiyyah.medium.com/a-simple-calculator-revisted-learnpythonthroughprojects-series-9-19ba4def4c4) 17 | 10. [Building a Simple PhoneBook](https://mardiyyah.medium.com/building-a-simple-phonebook-learnpythonthroughprojects-series-10-af56d527f463) 18 | 11. [Phonebook Program Revamped](https://mardiyyah.medium.com/phonebook-program-revamped-learnpythonthroughprojects-series-11-1dcaf33bf8e3) 19 | 12. [A Simple Hangman](https://mardiyyah.medium.com/a-simple-hangman-learnpythonthroughprojects-series-10-fedda58741b) 20 | 13. [Hangman with Image Display](https://mardiyyah.medium.com/hangman-with-image-display-series-13-learnpythonthroughprojects-a64742ceb089) 21 | 22 | 23 | I Hope you find these useful! 24 | -------------------------------------------------------------------------------- /WIDS_Lagos2020/Wids_Chatbot_Script.py: -------------------------------------------------------------------------------- 1 | 2 | #Import the random module 3 | import random 4 | 5 | #Create and store greetings and likely responses in a list data structure 6 | greetings = ["hola!I'm Annie", "hello! I'm Annie", 'hi!', 'Hi', 'hey!','hey',"What's up", 'Good day'] 7 | responses = ['Okay',"I'm fine","I'm doing great", "I'm ok","I'm good",'Good','Awesome', 'Great','Superb','nice','ok'] 8 | 9 | #question = ['How are you?','How are you doing?'] 10 | 11 | # Initiate a Welcome message and an introduction 12 | name = input('Welcome! What is your name?: ') 13 | print('>>>') 14 | print((random.choice(greetings),name,'!Nice to meet you')) 15 | 16 | #1st conversation 17 | feelings = input("How are you today?: ") 18 | 19 | if feelings.capitalize() in responses: 20 | print("I'm so Glad to hear that!") 21 | else: 22 | print('Oh dear!') 23 | print('Why do you feel', feelings) 24 | reason = input('Please tell me: ') 25 | print('I understand.It is absolutely ok to feel that way sometimes.Thanks for sharing') 26 | 27 | 28 | 29 | #2nd Conversation 30 | #Ask for user's age 31 | userAge = int(input('How old are you?: ')) 32 | if userAge >= 18 and userAge <= 24: 33 | print('Cool!You are a Young Adult') 34 | elif userAge >= 25 and userAge <= 44: 35 | print('Whoa!You are all grown up!') 36 | elif userAge > 45: 37 | print('Great!You seem like an elderly person') 38 | else: 39 | print('It feels so nice to be a teenager') 40 | 41 | #Conversation about continent 42 | world = ('Africa', 'Antractica','Asia', 'Australia', 'Europe','North-America', 'South-America') 43 | 44 | continent = input('What continent are you from?: ').capitalize() 45 | if continent in world and continent == 'Africa': 46 | print("That's cool! I have heard a lot about Africa and its richness for culture and nature parks") 47 | print('I sure would love to visit someday') 48 | elif continent in world and continent == 'Asia': 49 | print('Nice! Asians have a very unique culture. Beautiful culture, beautiful places, beautiful people.') 50 | elif continent in world and continent == 'Europe': 51 | print('Amazing!Europe is known for its unique building structures') 52 | elif continent in world and continent == 'Antractica': 53 | print('I heard the weather tends to get extreme over there and very few people live there. So glad to be chatting with a native') 54 | elif continent in world and continent == 'Australia': 55 | print('I would definitely love to visit sometime.I have a few friends from over there and they also tell me a lot of interesting stories') 56 | else: 57 | print('I have been to North-America a couple of times. I also love watching mexican movies. I think America is generally a rich continent') 58 | 59 | #Conversation on Year 60 | year = int(input('I am not very good at dates. What year is it?: ')) 61 | if year == 2020: 62 | print('You are very smart! It is the year of the global pandemic') 63 | print('Do stay safe at all times!') 64 | else: 65 | print('You are a genius! I have troubles remembering dates') 66 | 67 | #Ending the conversation 68 | print('I absolutely loved chatting with you today. Hope to talk to you some other time') 69 | print('Bye', name, '!You have quite an interesting personality. Do Take care!') 70 | --------------------------------------------------------------------------------