diff --git a/Python_Begginer_Projects/Amazing/3d_Surface_plot.py b/Python_Begginer_Projects/Amazing/3d_Surface_plot.py new file mode 100644 index 0000000..8185b17 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/3d_Surface_plot.py @@ -0,0 +1,33 @@ +import numpy as np +import matplotlib.pyplot as plt +from mpl_toolkits.mplot3d import Axes3D + +# Define the range of x and y values +x = np.linspace(-5, 5, 50) # Extending the range for more variation +y = np.linspace(-5, 5, 50) + +# Create meshgrid for X and Y +X, Y = np.meshgrid(x, y) + +# Calculate Z values for each combination of X and Y +Z = np.sin(np.sqrt(X**2 + Y**2)) + +# Create the plot +fig = plt.figure() +ax = fig.add_subplot(111, projection='3d') + +# Plot the surface with color map +surface = ax.plot_surface(X, Y, Z, cmap='viridis') + +# Add a colorbar with correct normalization +fig.colorbar(surface, ax=ax, shrink=0.5, aspect=5) + +# Set axis labels +ax.set_xlabel('X axis') +ax.set_ylabel('Y axis') +ax.set_zlabel('Z axis') + +# Display the plot +plt.show() + +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Amazing/Animated_Scatter_Plot.py b/Python_Begginer_Projects/Amazing/Animated_Scatter_Plot.py new file mode 100644 index 0000000..a33a5ff --- /dev/null +++ b/Python_Begginer_Projects/Amazing/Animated_Scatter_Plot.py @@ -0,0 +1,21 @@ +import plotly.express as px + +data = px.data.gapminder() + +fig = px.scatter( + data, + x='gdpPercap', + y='lifeExp', + animation_frame='year', + animation_group='country', + size='pop', + color='continent', + hover_name='country', + log_x=True, + size_max=60, + range_x=[200,600], + range_y=[20, 90], + title='Animated Scatter Plot: Life Expectancy vs GDP Per Capita' +) +fig.show() +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Amazing/Calender.py b/Python_Begginer_Projects/Amazing/Calender.py new file mode 100644 index 0000000..fa19063 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/Calender.py @@ -0,0 +1,6 @@ +# A simple calender disply app. +from calendar import TextCalendar +year = int(input('Enter a year: ')) +cal = TextCalendar() +print(cal.formatyear(year, 2, 1, 8, 3)) +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Amazing/Cosine_curve_plot.py b/Python_Begginer_Projects/Amazing/Cosine_curve_plot.py new file mode 100644 index 0000000..d79c99e --- /dev/null +++ b/Python_Begginer_Projects/Amazing/Cosine_curve_plot.py @@ -0,0 +1,12 @@ +import numpy as np +import matplotlib.pyplot as plt + +t = np.arange(0.0,2.0,0.01) +s = 1 + np.cos(2*np.pi*t) + +plt.grid() +plt.plot(t,s, '--') +plt.xlabel('Time (t)') +plt.ylabel('Voltage (v)') +plt.title('Cosine Curved plot') +plt.show() \ No newline at end of file diff --git a/Python_Begginer_Projects/Amazing/Countries_Details.py b/Python_Begginer_Projects/Amazing/Countries_Details.py new file mode 100644 index 0000000..0b52480 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/Countries_Details.py @@ -0,0 +1,31 @@ +from countryinfo import CountryInfo +try: + count = input('Enter the name of the country or -1 to quit: ') + while count != '-1': + + country = CountryInfo(count) + + print("Capital is: ", country.capital()) + print('----------------------------------------------------------------') + print('Currency is: ', country.currencies()) + print('----------------------------------------------------------------') + print('Language is: ', country.languages()) + print('----------------------------------------------------------------') + print('Borders are: ', country.borders()) + print('----------------------------------------------------------------') + print('Other names are: ', country.alt_spellings()) + print('----------------------------------------------------------------') + print('Population is: ', country.population()) + print('----------------------------------------------------------------') + print('Time zone is: ',country.timezones()) + print('----------------------------------------------------------------') + count = input('Enter the name of the country or -1 to quit: ') + print('----------------------------------------------------------------') + else: + print('Thanks for using the program...') +except KeyError: + print('Country was not found!') + print('Try Again with a valid country name.') + + +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Amazing/Histogram,_plot.py b/Python_Begginer_Projects/Amazing/Histogram,_plot.py new file mode 100644 index 0000000..660fd42 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/Histogram,_plot.py @@ -0,0 +1,12 @@ +import matplotlib.pyplot as plt + +ages = [2, 50, 70, 40,30,50,59,4,84,34,30,30,48,2,7,18,30,34,90,50] + +range =(0,100) +bins = 10 + +plt.hist(ages,bins, range, color='green', histtype='bar', rwidth=0.7) +plt.xlabel('Ages') +plt.ylabel('Bins') +plt.title('Histogram Plot') +plt.show() \ No newline at end of file diff --git a/Python_Begginer_Projects/Amazing/Periodic_Element_Data.py b/Python_Begginer_Projects/Amazing/Periodic_Element_Data.py new file mode 100644 index 0000000..da00191 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/Periodic_Element_Data.py @@ -0,0 +1,17 @@ +import periodictable + +# Prompt the user to input the atomic number +Atomic_Number = int(input('Enter the atomic number of the element: ')) + +# Use the `periodictable` module to get the element by its atomic number +element = periodictable.elements[Atomic_Number - 1] # Indexing starts at 0, so subtract 1 + +# Display the element's information +print("Name:", element.name) +print('----------------------') +print("Symbol:", element.symbol) +print('----------------------') +print("Atomic mass:", element.mass) +print('----------------------') +print("Atomic density:", element.density) +print('----------------------') diff --git a/Python_Begginer_Projects/Amazing/Pie_Chart.py b/Python_Begginer_Projects/Amazing/Pie_Chart.py new file mode 100644 index 0000000..0f66260 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/Pie_Chart.py @@ -0,0 +1,10 @@ +import matplotlib.pyplot as plt + +labels = ('Python', 'Java', 'JavaScript', 'C++') +sizes =[45, 19, 16, 20] + +plt.pie(sizes, + labels=labels, autopct='%1.f%%', + counterclock=False, startangle=105) + +plt.show() \ No newline at end of file diff --git a/Python_Begginer_Projects/Amazing/World_Map.py b/Python_Begginer_Projects/Amazing/World_Map.py new file mode 100644 index 0000000..535d854 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/World_Map.py @@ -0,0 +1,8 @@ +import geopandas as gpd +import matplotlib.pyplot as plt + +world = gpd.read_file('Python_Begginer_Projects/Amazing/ne_110m_admin_0_countries.shp') +# main function to display the map +world.plot(edgecolor='red') +plt.title('World Map with Country Borders') +plt.show() diff --git a/Python_Begginer_Projects/Amazing/heart.py b/Python_Begginer_Projects/Amazing/heart.py new file mode 100644 index 0000000..98a1b1e --- /dev/null +++ b/Python_Begginer_Projects/Amazing/heart.py @@ -0,0 +1,20 @@ +import math +from turtle import * + +def heart(x): + return 12*math.sin(x) ** 3 + +def show(x): + return 12 * math.cos(x) - 5 * math.cos(2 * x) - 2 * math.cos(4 * x) + +speed(0) +bgcolor('black') + +for i in range(10000): + x = heart(i) * 20 + y = show(i) * 20 + goto(x, y) + for j in range(5): + color('#f73487') + goto(x,0) +done() \ No newline at end of file diff --git a/Python_Begginer_Projects/Amazing/image_mirror.pu b/Python_Begginer_Projects/Amazing/image_mirror.pu new file mode 100644 index 0000000..a49da4e --- /dev/null +++ b/Python_Begginer_Projects/Amazing/image_mirror.pu @@ -0,0 +1,10 @@ +from PIL import Image + + +Original_Image = 'pushpa.png' +Image. open(Original_Image) +img = Image.open(Original_Image) +Mirror_Image = img.transpose(Image.FLIP_LEFT_RIGHT) +Mirrored_Image = 'pushpa_mirror.png' +Mirror_Image.save(Mirrored_Image) +Image.open(Mirrored_ Image) \ No newline at end of file diff --git a/Python_Begginer_Projects/Amazing/ne_110m_admin_0_countries.shp b/Python_Begginer_Projects/Amazing/ne_110m_admin_0_countries.shp new file mode 100644 index 0000000..9318e45 Binary files /dev/null and b/Python_Begginer_Projects/Amazing/ne_110m_admin_0_countries.shp differ diff --git a/Python_Begginer_Projects/Amazing/notifications.py b/Python_Begginer_Projects/Amazing/notifications.py new file mode 100644 index 0000000..f949b85 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/notifications.py @@ -0,0 +1,8 @@ +from plyer import notification +# Send notification +notification.notify( +title="Reminder", +message="Take a break and stretch!", +app_name="Python Notifier", +timeout=10 +) \ No newline at end of file diff --git a/Python_Begginer_Projects/Amazing/play_youtube_video.py b/Python_Begginer_Projects/Amazing/play_youtube_video.py new file mode 100644 index 0000000..57c436a --- /dev/null +++ b/Python_Begginer_Projects/Amazing/play_youtube_video.py @@ -0,0 +1,9 @@ +import pywhatkit +try: + + Song = input("Enter Song Name: ") + pywhatkit.playonyt (Song) + print("Successfully Played!") + +except: + print("An Unexpected Error!") \ No newline at end of file diff --git a/Python_Begginer_Projects/Amazing/sunburst_chart.py b/Python_Begginer_Projects/Amazing/sunburst_chart.py new file mode 100644 index 0000000..63b11d5 --- /dev/null +++ b/Python_Begginer_Projects/Amazing/sunburst_chart.py @@ -0,0 +1,18 @@ +import plotly.graph_objects as go + +labels = ["Root", "Branch 1","Branch 2", "Leaf 1", "Leaf 2", "Leaf 3"] + +parents = ['', "Root","Root", "Branch 1", "Branch 1", "Branch 2"] + +values = [10, 5, 5, 2, 3, 5] + +fig = go.Figure(go.Sunburst(labels=labels, +parents=parents, +values=values, +branchvalues="total" )) + +fig. update_layout( +title="Sunburst Chart in Python", +margin=dict (t=30, l=0, r=0, b=0)) + +fig. show() diff --git a/Python_Begginer_Projects/Easy/Palindrome.py b/Python_Begginer_Projects/Easy/Palindrome.py new file mode 100644 index 0000000..f9f2bfe --- /dev/null +++ b/Python_Begginer_Projects/Easy/Palindrome.py @@ -0,0 +1,54 @@ +# Palindrome checker Program + +def Start(): # A function to start the program + print('----Heyyy, Welcome to the Palindrome Checker----') + print('----------------------------------------------------------------') + + while True: # Loop the program until a says no. + choice = input('Do you want to start? (Yes or No): ').lower() + + if choice == 'yes': + main() + + elif choice == 'no': + print('--------------------------------') + print('Thanks for time...') + break + + else: + print('Please enter yes or no') + print() + print('----------------------------------------------------------------') + +def accept_word(): # A function to accept user word. + word = input('Enter the word or a number: ') + + print('----------------------------------------------------------------') + return word + +def Check_Palindrome(word): # A function to check whether a word is a palindrome or not. + + if word == word[::-1]: # A condition if the reserved word is same as the actual word. + + if word.isdigit():# A condition if the word is a digit for numbers. + print(f'The number "{word}" is a palindrome.') + else: + print(f'The word "{word}" is a palindrome.') + + else: # An otherwise condition for word that are not a palindrome. + if word.isdigit():# A condition if the word is a digit for numbers. + print(f'The number "{word}" is not a palindrome.') + else: + print(f'The word "{word}" is not a palindrome.') + + print('----------------------------------------------------------------') + +def main(): # Main function to take words and check if they are a palindrome or not. + + word = accept_word() + print('----------------------------------------------------------------') + Check_Palindrome(word) + + +if __name__ == '__main__': + Start() diff --git a/Python_Begginer_Projects/Easy/factorial.py b/Python_Begginer_Projects/Easy/factorial.py new file mode 100644 index 0000000..7d23d1c --- /dev/null +++ b/Python_Begginer_Projects/Easy/factorial.py @@ -0,0 +1,10 @@ +number = int(input('Enter a number: ')) + +def Cal(number): + if(number == 1): + return 1 + else: + return number * Cal(number - 1) + +a = Cal(number) +print(number, '! =', a) diff --git a/Python_Begginer_Projects/Easy/magic8.py b/Python_Begginer_Projects/Easy/magic8.py new file mode 100644 index 0000000..695ebf6 --- /dev/null +++ b/Python_Begginer_Projects/Easy/magic8.py @@ -0,0 +1,33 @@ +import random + +responses = [ + "Yes, definitely.", + "As I see it, yes.", + "Reply hazy, try again.", + "Cannot predict now.", + "Do not count on it.", + "My sources say no.", + "Outlook not so good.", + "Very doubtful." +] + +def magic_8_ball(): + print("Welcome to the Magic 8 Ball! Ask a yes/no question.") + + while True: + question = input("Ask your question (or type 'quit' to exit): ") + + if question.lower() == 'quit': + print("Thanks for playing! Goodbye!") + break + + if question.strip() == "": + print("Please ask a valid question.") + continue + + # Get a random response + answer = random.choice(responses) + print("Magic 8 Ball says:", answer) + +# Run the program +magic_8_ball() diff --git a/Python_Begginer_Projects/Easy/time_table.py b/Python_Begginer_Projects/Easy/time_table.py new file mode 100644 index 0000000..be7a7ff --- /dev/null +++ b/Python_Begginer_Projects/Easy/time_table.py @@ -0,0 +1,16 @@ +def calculate(): + n = range(1, 13) + for i in n: + print(i, "Times Table") + print('-----------------------------------') + for j in n: + print(i, 'x', j,"=", i*j) + print() + + print('-----------------------------------') + +def main(): + + calculate() + +main() diff --git a/Python_Begginer_Projects/Intermediate/Calculator/Calculator.py b/Python_Begginer_Projects/Intermediate/Calculator/Calculator.py new file mode 100644 index 0000000..2707038 --- /dev/null +++ b/Python_Begginer_Projects/Intermediate/Calculator/Calculator.py @@ -0,0 +1,22 @@ +class calculate: + def __init__(self, first_number, second_number): + + self.first_numbeer = first_number + self.second_number = second_number + + + + def add(self): + return self.first_numbeer + self.second_number + + def mul(self): + return self.first_numbeer * self.second_number + + def sub(self): + return self.first_numbeer - self.second_number + + def div(self): + if self.second_number != 0: + return self.first_numbeer / self.second_number + else: + return f'Division by zero is invalid...' diff --git a/Python_Begginer_Projects/Intermediate/Calculator/__pycache__/Calculator.cpython-312.pyc b/Python_Begginer_Projects/Intermediate/Calculator/__pycache__/Calculator.cpython-312.pyc new file mode 100644 index 0000000..8dd3c18 Binary files /dev/null and b/Python_Begginer_Projects/Intermediate/Calculator/__pycache__/Calculator.cpython-312.pyc differ diff --git a/Python_Begginer_Projects/Intermediate/Calculator/main.py b/Python_Begginer_Projects/Intermediate/Calculator/main.py new file mode 100644 index 0000000..b701217 --- /dev/null +++ b/Python_Begginer_Projects/Intermediate/Calculator/main.py @@ -0,0 +1,108 @@ +from Calculator import calculate # import a class module I wrote in Calculator.py called calculate + +signs = { # A dictionary to store signs according to user choices from menu + 1:'+', + 2:'-', + 3:'x', + 4:'/' +} + +def display_menu(): # A method to display menu options to users + print( + '''---Menu--- + 1. Addition + 2. Subtraction + 3. Multiplication + 4. Division + 5. Quit + + ''' + ) + accept_user_choice() # Calling a function that accepts user menu choices. + +def accept_user_choice(): # A Method to accept user choices + + user_choice = input('Enter a choice from (1 - 5): ') # a prompt variable to accept user choice and store them as string + + if user_choice.isdigit(): # a condition to check if the user choice is a digit or not. + user_choice = int(user_choice) # converting user choices from str to int after being a digit + validate_user_choice(user_choice) # calling the validation method to validate if user choice is true. + + else: # An else statement to prompt errors + print('Invalid user choice...') + accept_user_choice() # using recursion method to run this method to re-accept the user choice till conditions are met + + + + +def validate_user_choice(choice): # a method to validate user choices for the menu options + if 0 < choice < 5: # choices from users should be from (1 - 5) but 5 is an exception to quit the program + display_results(choice) # display results after conditions are met + + + elif choice == 5: # quit the program if a uer choice is 5 + print('Quiting...') + quit() + + else: # a prompt condition to alert users to enter a choice from 1-5 + print('Choice must be from 1 - 5') + accept_user_choice() # calling this method to accept new user choices + +def assign_user_choice_to_menu_option(x, y,choice): # a method to assign various choices to appropriate calculations + + cal = calculate(x, y) # creating an object for the class calculate to be used in calling various class methods. + + if choice == 1: + return cal.add() + elif choice == 2: + return cal.sub() + elif choice == 3: + return cal.mul() + else: + return cal.div() + + +def accept_values(): # A method to accept user values for calculations + + x = input('Enter value 1: ') + y = input('Enter value 2: ') + + if (x and y).isdigit(): # Checking if valuses are digit then it's converted into float + x = float(x) + y = float(y) + + else: # a case where values are not digits + print('Please enter a digit / a number... ') + accept_values() + return x, y + +def display_results(choice):# method to display the answer + x, y = accept_values() + + answer = assign_user_choice_to_menu_option(x, y, choice) # calling this method to assign user choice to right menu option + + for key, pair in signs.items(): # using a for loop to print the answer with the appropriate sign + if key == choice: + print(f'{x} {pair} {y} = {answer}') + + + + + +def main(): # main loop + print('--Calculator--') + while True: + display_menu() # calling this function to start the process + + again = input('Do you want to continue (n / y): ').lower() # a prompt to ask users for continuation + if again != 'y': + quit() + break + else: + print(' ') + + +if __name__ == '__main__': # running from the mainloop... + main() + +#mMabiaa \ No newline at end of file diff --git a/Python_Begginer_Projects/Intermediate/City_Quiz.py b/Python_Begginer_Projects/Intermediate/City_Quiz.py index 0bae92c..c981864 100644 --- a/Python_Begginer_Projects/Intermediate/City_Quiz.py +++ b/Python_Begginer_Projects/Intermediate/City_Quiz.py @@ -74,5 +74,5 @@ def display_Quiz(quiz, score): - +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/Currency_Convertor.py b/Python_Begginer_Projects/Intermediate/Currency_Convertor.py index efc00dc..4137a7f 100644 --- a/Python_Begginer_Projects/Intermediate/Currency_Convertor.py +++ b/Python_Begginer_Projects/Intermediate/Currency_Convertor.py @@ -53,4 +53,5 @@ def main(): print('') -main() \ No newline at end of file +main() +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/Email_sender/main.py b/Python_Begginer_Projects/Intermediate/Email_sender/main.py index 8a0bf93..9f7d823 100644 --- a/Python_Begginer_Projects/Intermediate/Email_sender/main.py +++ b/Python_Begginer_Projects/Intermediate/Email_sender/main.py @@ -40,4 +40,5 @@ def Main(): print(" ") print('Email sent successfully!') -Main() \ No newline at end of file +Main() +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/Email_sender/variables.py b/Python_Begginer_Projects/Intermediate/Email_sender/variables.py index 1895ef1..30a7126 100644 --- a/Python_Begginer_Projects/Intermediate/Email_sender/variables.py +++ b/Python_Begginer_Projects/Intermediate/Email_sender/variables.py @@ -1 +1 @@ -password = 'dffk pipb gsbm vgba' \ No newline at end of file +password = 'password' diff --git a/Python_Begginer_Projects/Intermediate/Face Dention Program/main.py b/Python_Begginer_Projects/Intermediate/Face Dention Program/main.py index 2ca305b..d947b49 100644 --- a/Python_Begginer_Projects/Intermediate/Face Dention Program/main.py +++ b/Python_Begginer_Projects/Intermediate/Face Dention Program/main.py @@ -43,3 +43,4 @@ # Release the video capture object and close any OpenCV windows video_capture.release() cv2.destroyAllWindows() +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/Qr_Code_Generator/qr_code_generator.py b/Python_Begginer_Projects/Intermediate/Qr_Code_Generator/qr_code_generator.py index 7d9c2f7..47c6393 100644 --- a/Python_Begginer_Projects/Intermediate/Qr_Code_Generator/qr_code_generator.py +++ b/Python_Begginer_Projects/Intermediate/Qr_Code_Generator/qr_code_generator.py @@ -12,3 +12,4 @@ def Main(): print(f"QR code saved as {filename}") Main() +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/TextMessage_Automation.py b/Python_Begginer_Projects/Intermediate/TextMessage_Automation.py index 1b9fa5d..fbb2a30 100644 --- a/Python_Begginer_Projects/Intermediate/TextMessage_Automation.py +++ b/Python_Begginer_Projects/Intermediate/TextMessage_Automation.py @@ -15,3 +15,4 @@ def send_message(): # Schedule at 6pm everyday. schedule.every().day.at('18:00').do(send_message) +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/binary_search.py b/Python_Begginer_Projects/Intermediate/binary_search.py index aebc4e3..1f736a2 100644 --- a/Python_Begginer_Projects/Intermediate/binary_search.py +++ b/Python_Begginer_Projects/Intermediate/binary_search.py @@ -36,4 +36,4 @@ def main(): - +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/calculator.py b/Python_Begginer_Projects/Intermediate/calculator.py index 541cdc1..dfb46d4 100644 --- a/Python_Begginer_Projects/Intermediate/calculator.py +++ b/Python_Begginer_Projects/Intermediate/calculator.py @@ -57,4 +57,5 @@ def Main(): # A main function to run and test the program print(result) -Main() # CAll the Main function to run the program \ No newline at end of file +Main() # CAll the Main function to run the program +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/contact_management.py b/Python_Begginer_Projects/Intermediate/contact_management.py new file mode 100644 index 0000000..e33b7dd --- /dev/null +++ b/Python_Begginer_Projects/Intermediate/contact_management.py @@ -0,0 +1,57 @@ +def add_contact(contacts): + name = input("Enter contact name: ") + phone = input("Enter contact phone number: ") + contacts.append({"name": name, "phone": phone}) + print(f"Contact '{name}' added successfully.\n") + +def view_contacts(contacts): + if not contacts: + print("No contacts available.\n") + return + print("Contacts List:") + for idx, contact in enumerate(contacts, start=1): + print(f"{idx}. Name: {contact['name']}, Phone: {contact['phone']}") + print() # Add a new line for better readability + +def delete_contact(contacts): + view_contacts(contacts) + if not contacts: + return + try: + index = int(input("Enter the number of the contact to delete: ")) - 1 + if 0 <= index < len(contacts): + removed_contact = contacts.pop(index) + print(f"Contact '{removed_contact['name']}' deleted successfully.\n") + else: + print("Invalid contact number.\n") + except ValueError: + print("Please enter a valid number.\n") + +def main_menu(): + contacts = [] + + while True: + print("Contact Management System") + print("1. Add Contact") + print("2. View Contacts") + print("3. Delete Contact") + print("4. Exit") + + choice = input("Select an option (1-4): ") + + if choice == '1': + add_contact(contacts) + elif choice == '2': + view_contacts(contacts) + elif choice == '3': + delete_contact(contacts) + elif choice == '4': + print("Exiting the program. Goodbye!") + break + else: + print("Invalid choice. Please select a valid option.\n") + +if __name__ == "__main__": + main_menu() + +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/hangman.py b/Python_Begginer_Projects/Intermediate/hangman.py new file mode 100644 index 0000000..4726e4d --- /dev/null +++ b/Python_Begginer_Projects/Intermediate/hangman.py @@ -0,0 +1,115 @@ +import random + +def choose_word(): + words = ["python", "hangman", "programming", "developer", "challenge"] + return random.choice(words) + +def display_hangman(tries): + stages = [ + """ + ------ + | | + | O + | /|\ + | /|\ + | + """, + """ + ------ + | | + | O + | /|\ + | / \ + | + """, + """ + ------ + | | + | O + | /|\ + | + | + """, + """ + ------ + | | + | O + | | + | + | + """, + """ + ------ + | | + | O + | + | + | + """, + """ + ------ + | | + | + | + | + | + """, + """ + + """, + ] + return stages[tries] + +def play_hangman(): + word = choose_word() + word_completion = "_" * len(word) + guessed = False + guessed_letters = [] + guessed_words = [] + tries = 6 + + print("Let's play Hangman!") + + while not guessed and tries > 0: + print(display_hangman(tries)) + print(word_completion) + guess = input("Please guess a letter or word: ").lower() + + if len(guess) == 1 and guess.isalpha(): + if guess in guessed_letters: + print("You already guessed that letter.") + elif guess not in word: + print("Sorry, that letter is not in the word.") + tries -= 1 + guessed_letters.append(guess) + else: + print("Good job! That letter is in the word.") + guessed_letters.append(guess) + word_completion = "".join([guess if letter == guess else word_completion[i] for i, letter in enumerate(word)]) + + if "_" not in word_completion: + guessed = True + + elif len(guess) == len(word) and guess.isalpha(): + if guess in guessed_words: + print("You already guessed that word.") + elif guess != word: + print("Sorry, that's not the word.") + tries -= 1 + guessed_words.append(guess) + else: + guessed = True + word_completion = word + + else: + print("Invalid input. Please try again.") + + if guessed: + print(f"Congratulations! You've guessed the word '{word}' correctly!") + else: + print(display_hangman(tries)) + print(f"Sorry, you've run out of tries. The word was '{word}'.") + +if __name__ == "__main__": + play_hangman() + # Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/mad_lib.py b/Python_Begginer_Projects/Intermediate/mad_lib.py new file mode 100644 index 0000000..ef45b5f --- /dev/null +++ b/Python_Begginer_Projects/Intermediate/mad_lib.py @@ -0,0 +1,70 @@ +# Mad Libs Project: Tragic and Hilarious Stories + +def get_input(prompt): + """Function to get user input with a prompt.""" + return input(prompt) + +def create_tragic_story(elderly_woman_name, grandson_name): + """Generate the tragic story using provided names.""" + tragic_story_template = """ + In a quiet hospital room, an elderly woman named {elderly_woman_name} lay in bed, her memories fading. + Every day, her grandson {grandson_name} visited, hoping to spark recognition. + One day, he brought a photo of their last vacation together, but she only stared blankly. + As he held her hand, he whispered, 'I love you,' knowing this might be their final moment together. + """ + + return tragic_story_template.format( + elderly_woman_name=elderly_woman_name, + grandson_name=grandson_name + ) + +def create_hilarious_story(owner_name, cat_name, adjective, cat_action, dog_action, noun): + """Generate the hilarious story using provided inputs.""" + hilarious_story_template = """ + One sunny afternoon, {owner_name} decided to train their cat {cat_name} to fetch. + Armed with a {adjective} toy, they threw it across the yard. + To their surprise, the cat {cat_action} instead of fetching! + The neighbor's dog {dog_action} in confusion as the cat proudly strutted back with a {noun} instead! + """ + + return hilarious_story_template.format( + owner_name=owner_name, + cat_name=cat_name, + adjective=adjective, + cat_action=cat_action, + dog_action=dog_action, + noun=noun + ) + +def main(): + """Main function to run the Mad Libs project.""" + + # Gather user input for the tragic story + print("Let's create a tragic story!") + elderly_woman_name = get_input("Enter the name of the elderly woman: ") + grandson_name = get_input("Enter the name of the grandson: ") + + # Generate and display the tragic story + tragic_story = create_tragic_story(elderly_woman_name, grandson_name) + print("\nHere is your tragic Mad Libs story:") + print(tragic_story) + + # Gather user input for the hilarious story + print("Now, let's create a hilarious story!") + owner_name = get_input("Enter the name of the cat owner: ") + cat_name = get_input("Enter the name of the cat: ") + adjective = get_input("Enter an adjective: ") + cat_action = get_input("Enter a verb (what the cat does): ") + dog_action = get_input("Enter a verb (what the dog does): ") + noun = get_input("Enter a noun: ") + + # Generate and display the hilarious story + hilarious_story = create_hilarious_story(owner_name, cat_name, adjective, cat_action, dog_action, noun) + print("\nHere is your hilarious Mad Libs story:") + print(hilarious_story) + +# Entry point for the program +if __name__ == "__main__": + main() + +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Intermediate/words_dictionary.py b/Python_Begginer_Projects/Intermediate/words_dictionary.py index 670b480..17060e8 100644 --- a/Python_Begginer_Projects/Intermediate/words_dictionary.py +++ b/Python_Begginer_Projects/Intermediate/words_dictionary.py @@ -59,3 +59,4 @@ def Main(): # Calling the main function Main() +# Author - Mmabiaa diff --git a/Python_Begginer_Projects/Shapes/right_angle_tringle.py b/Python_Begginer_Projects/Shapes/right_angle_tringle.py new file mode 100644 index 0000000..de23129 --- /dev/null +++ b/Python_Begginer_Projects/Shapes/right_angle_tringle.py @@ -0,0 +1,27 @@ +def Square(s): + for i in range(s): + if i == 0: # First row + print('*') + elif i == s - 1: # Last row + print('* ' * s) + else: # Middle rows + print('*' + ' ' * (2 * i - 1) + '*') +def check_length(): + while True: + length = input('Enter the length of the triangle: ') + if length.isdigit(): + length = int(length) + if length > 1: + Square(length) + else: + print('Length must be greater than one.') + else: + print('Please enter a digit.') + + +check_length() + +if __name__ == '__main__': + check_length() +# Author - Mmabiaa + diff --git a/Python_Begginer_Projects/Shapes/square.py b/Python_Begginer_Projects/Shapes/square.py new file mode 100644 index 0000000..84e7974 --- /dev/null +++ b/Python_Begginer_Projects/Shapes/square.py @@ -0,0 +1,34 @@ +# simple square +def accept_square_size(): # A function to accept square size + size = input('Enter the size of the square: ') + return size + + +def validate_square_size(): # A function to validate square size + size = accept_square_size() + + if size.isdigit(): + size = int(size) + if size > 1: + draw_square(size) + else: + print('Size must be greater than one!') + else: + print('Size must be a digit!') + +def draw_square(size): # A function to draw a square + + for i in range(size): + if i == size-1 or i == 0: + print('* '*size) + else: + print('* '+ ' '*(size-2)+ '*') + +def display_square(): # A function that displays the square + validate_square_size() + + +if __name__ == '__main__': # main function + display_square() + + # Author - Mmabiaa