import random import math import string def backpack_umbrella_program(): while True: print("Backpack Umbrella Program:") print("1. Flashcards & Quiz Game") print("2. Calculator") print("3. Random Number Generator") print("4. Unit Converter") print("5. Password Generator") print("0. Exit") choice = input("Enter your choice: ") print() if choice == "0": print("Exiting the program.") break elif choice == "1": def flashcards_quiz(): print("Welcome to Flashcards & Quiz Game!") flashcard_set = {} while True: print("Menu:") print("1. Add Flashcard") print("2. Start Flashcard Session") print("3. Start Quiz Game") print("0. Go Back") choice = input("Enter your choice: ") print() if choice == "0": print("Returning to main menu.") break elif choice == "1": question = input("Enter a question: ") answer = input("Enter the answer: ") flashcard_set[question] = answer print("Flashcard added successfully!") print() elif choice == "2": if not flashcard_set: print("No flashcards available. Please add flashcards first.") continue print("Starting the flashcard session...") for question, answer in flashcard_set.items(): print(question) input("Press enter to reveal the answer...") print("Answer:", answer) print() elif choice == "3": if not flashcard_set: print("No flashcards available. Please add flashcards first.") continue print("Starting the quiz game...") questions = list(flashcard_set.keys()) random.shuffle(questions) score = 0 for question in questions: print(question) user_answer = input("Your answer: ") if user_answer.lower() == flashcard_set[question].lower(): print("Correct!") score += 1 else: print("Incorrect!") print() print("Quiz game ended.") print("Your score:", score, "out of", len(questions)) print() else: print("Invalid choice. Please try again.") print() print() choice = input("press 0 to go back to start; or Enter to continue; ") if choice == "0": print("Exiting the program.") print() break flashcards_quiz() elif choice == "2": def calculator(): while True: print("Starting calculator...") print() print("Menu:") print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") print("5. Exponentiation") print("6. Square root") print("7. Trigonometric operations") print("8. Logarithmic operations") print("0. Go Back") choice = input("Select one of the above operations: ") print() if choice == "0": print("Returning to main menu.") break elif choice == "1": n1 = float(input("First number: ")) n2 = float(input("Second number: ")) sum = n1 + n2 print("Your answer is:", sum) print() elif choice == "2": n1 = float(input("First number: ")) n2 = float(input("Second number: ")) difference = n1 - n2 print("Your answer is:", difference) print() elif choice == "3": n1 = float(input("First number: ")) n2 = float(input("Second number: ")) product = n1 * n2 print("Your answer is:", product) print() elif choice == "4": n1 = float(input("First number: ")) n2 = float(input("Second number: ")) if n2 != 0: quotient = n1 / n2 print("Your answer is:", quotient) print() else: print("Error: Division by zero is not allowed.") print() elif choice == "5": n1 = float(input("Base: ")) n2 = float(input("Exponent: ")) power = n1 ** n2 print("Your answer is:", power) print() elif choice == "6": n = float(input("Number: ")) if n >= 0: sqrt = math.sqrt(n) print("Square root:", sqrt) print() else: print("Error: Square root of a negative number is not defined.") print() elif choice == "7": angle = float(input("Enter the angle in degrees: ")) print("1. Sine") print("2. Cosine") print("3. Tangent") trig_choice = input("Enter the number corresponding to the trigonometric function you want to calculate: ") if trig_choice == "1": result = math.sin(math.radians(angle)) print("Sine:", result) elif trig_choice == "2": result = math.cos(math.radians(angle)) if math.isclose(result, 0.0, abs_tol=1e-9): result = 0.0 print("Cosine:", result) elif trig_choice == "3": if angle % 180 == 90: print("Tangent: Undefined") else: result = math.tan(math.radians(angle)) print("Tangent:", result) else: print("Invalid choice.") print() elif choice == "8": print("Logarithmic Operations:") print("1. Natural Logarithm (base e)") print("2. Logarithm (base 10)") operation_choice = input("Select one of the above operations: ") print() if operation_choice == "1": n = float(input("Number: ")) if n > 0: result = math.log(n) print("Natural logarithm of", n, "is:", result) print() else: print("Error: Logarithm of a non-positive number is not defined.") print() elif operation_choice == "2": n = float(input("Number: ")) if n > 0: result = math.log10(n) print("Logarithm (base 10) of", n, "is:", result) print() else: print("Error: Logarithm of a non-positive number is not defined.") print() else: print("Invalid choice. Please try again.") print() else: print("Invalid choice. Please try again.") print() print() choice = input("press 0 to go back to start; or Enter to continue: ") if choice == "0": print("Exiting the program.") print() break calculator() elif choice == "3": def random_number_generator(): while True: print("Random Number Generator") print("Menu:") print("1. Generate random integer") print("2. Generate random floating-point number") print("0. Go Back") choice = input("Enter your choice: ") print() if choice == "0": print("Returning to main menu.") return elif choice == "1": start = int(input("Enter the starting range: ")) end = int(input("Enter the ending range: ")) random_integer = random.randint(start, end) print("Random integer between", start, "and", end, "is:", random_integer) print() elif choice == "2": start = float(input("Enter the starting range: ")) end = float(input("Enter the ending range: ")) random_float = random.uniform(start, end) print("Random floating-point number between", start, "and", end, "is:", random_float) print() else: print("Invalid choice. Please try again.") print() print() choice = input("press 0 to go back to start; or Enter to continue: ") if choice == "0": print("Exiting the program.") print() break random_number_generator() elif choice == "4": def unit_converter(): while True: print("Welcome to the Unit Converter!") print("1. Length Conversion") print("2. Temperature Conversion") print("3. Mass Conversion") choice = input("Enter the number corresponding to the conversion you want to perform: ") if choice == "1": print("1. Kilometer to Mile") print("2. Mile to Kilometer") print("3. Meter to Yard") print("4. Yard to Meter") print("5. Inch to Centimeter") print("6. Centimeter to Inch") conversion_choice = input("Enter the number corresponding to the conversion you want to perform: ") if conversion_choice == "1": km = float(input("Enter the distance in kilometers: ")) miles = km * 0.621371 print("Distance in miles:", miles) elif conversion_choice == "2": miles = float(input("Enter the distance in miles: ")) km = miles / 0.621371 print("Distance in kilometers:", km) elif conversion_choice == "3": meters = float(input("Enter the distance in meters: ")) yards = meters * 1.09361 print("Distance in yards:", yards) elif conversion_choice == "4": yards = float(input("Enter the distance in yards: ")) meters = yards / 1.09361 print("Distance in meters:", meters) elif conversion_choice == "5": inches = float(input("Enter the distance in inches: ")) cm = inches * 2.54 print("Distance in centimeters:", cm) elif conversion_choice == "6": cm = float(input("Enter the distance in centimeters: ")) inches = cm / 2.54 print("Distance in inches:", inches) else: print("Invalid choice.") elif choice == "2": print("1. Celsius to Fahrenheit") print("2. Fahrenheit to Celsius") conversion_choice = input("Enter the number corresponding to the conversion you want to perform: ") if conversion_choice == "1": celsius = float(input("Enter the temperature in Celsius: ")) fahrenheit = (celsius * 9/5) + 32 print("Temperature in Fahrenheit:", fahrenheit) elif conversion_choice == "2": fahrenheit = float(input("Enter the temperature in Fahrenheit: ")) celsius = (fahrenheit - 32) * 5/9 print("Temperature in Celsius:", celsius) else: print("Invalid choice.") elif choice == "3": print("1. Kilogram to Pound") print("2. Pound to Kilogram") conversion_choice = input("Enter the number corresponding to the conversion you want to perform: ") if conversion_choice == "1": kg = float(input("Enter the mass in kilograms: ")) pounds = kg * 2.20462 print("Mass in pounds:", pounds) elif conversion_choice == "2": pounds = float(input("Enter the mass in pounds: ")) kg = pounds / 2.20462 print("Mass in kilograms:", kg) else: print("Invalid choice.") else: print("Invalid choice.") print() choice = input("press 0 to go back to start; or Enter to continue: ") if choice == "0": print("Exiting the program.") print() break unit_converter() elif choice == "5": def generate_password(length=8, include_lowercase=True, include_uppercase=True, include_digits=True, include_symbols=True): characters = "" if include_lowercase: characters += string.ascii_lowercase if include_uppercase: characters += string.ascii_uppercase if include_digits: characters += string.digits if include_symbols: characters += string.punctuation if not characters: print("Error: No character set selected. Please enable at least one character set.") return "" password = "".join(random.choice(characters) for _ in range(length)) return password def password_generator(): while True: print("Password Generator") print("Options:") print("1. Generate Password") print("0. Exit") choice = input("Enter your choice: ") if choice == "0": print("Exiting the program.") break elif choice == "1": length = int(input("Enter the password length: ")) include_lowercase = input("Include lowercase letters? (y/n): ").lower() == "y" include_uppercase = input("Include uppercase letters? (y/n): ").lower() == "y" include_digits = input("Include digits? (y/n): ").lower() == "y" include_symbols = input("Include symbols? (y/n): ").lower() == "y" password = generate_password(length, include_lowercase, include_uppercase, include_digits, include_symbols) print("Generated Password:", password) else: print("Invalid choice. Please try again.") print() choice = input("press 0 to go back to start, or Enter to continue") if choice == "0": print("Exiting the program.") print() break password_generator() else: print("Invalid choice. Please try again.") print() backpack_umbrella_program()