# Movie database with different categories (Indian movies)
movies = {
"action": [
"The Dark Knight",
"Mad Max: Fury Road",
"John Wick",
"Gladiator",
"Die Hard",
"Baahubali 2: The Conclusion",
"War",
"KGF: Chapter 1",
"Singham",
"Vikram Vedha"
],
"comedy": [
"Hera Pheri",
"Andaz Apna Apna",
"Golmaal: Fun Unlimited",
"Dhamaal",
"3 Idiots",
"The Hangover",
"Superbad",
"Step Brothers",
"Bridesmaids",
"Dumb and Dumber"
],
"drama": [
"Lagaan: Once Upon a Time in India",
"Taare Zameen Par",
"Dangal",
"Swades",
"Rang De Basanti",
"The Shawshank Redemption",
"Forrest Gump",
"The Godfather",
"Schindler's List",
"Fight Club"
],
"horror": [
"Tumbbad",
"Pari",
"1920",
"Raaz",
"Bhoot",
"The Exorcist",
"Hereditary",
"The Shining",
"Get Out",
"A Quiet Place"
],
"sci-fi": [
"Robot (Enthiran)",
"2.0",
"Koi... Mil Gaya",
"Tik Tik Tik",
"Mr. India",
"Inception",
"Interstellar",
"The Matrix",
"Blade Runner 2049",
"Star Wars: The Empire Strikes Back"
],
"animation": [
"Spirited Away",
"The Lion King",
"Toy Story",
"Your Name",
"Spider-Man: Into the Spider-Verse"
]
}
def recommend_movies():
print("Welcome to Movie Recommender!")
print("Available categories:")
# Display categories with numbers
categories = list(movies.keys())
for i, category in enumerate(categories, 1):
print(f"{i}. {category.capitalize()}")
while True:
choice = input("\nEnter category number/name (or 'exit' to quit): ").strip().lower()
if choice == 'exit':
print("Goodbye!")
break
# Handle numeric input
if choice.isdigit():
num = int(choice)
if 1 <= num <= len(categories):
selected = categories[num-1]
else:
print("Invalid number! Please try again.")
continue
# Handle text input
elif choice in categories:
selected = choice
else:
print("Invalid category! Please try again.")
continue
# Display recommendations
print(f"\nRecommended {selected} movies:")
for movie in movies[selected]:
print(f"- {movie}")
# Ask to continue
cont = input("\nWant more recommendations? (y/n): ").lower()
if cont != 'y':
print("Thanks for using Movie Recommender!")
break
# Run the program
recommend_movies()
import random
def learn_numbers():
print("\nNumbers 1-10:")
for i in range(1, 11):
print(i, end=' ')
print("\n")
def learn_lowercase():
print("\nLowercase letters a-z:")
for c in 'abcdefghijklmnopqrstuvwxyz':
print(c, end=' ')
print("\n")
def learn_uppercase():
print("\nUppercase letters A-Z:")
for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
print(c, end=' ')
print("\n")
def run_test(category):
score = 0
questions = 5 # Number of test questions
for _ in range(questions):
if category == 'numbers':
correct = str(random.randint(1, 10))
print(f"Enter the NUMBER: {correct}")
elif category == 'lowercase':
correct = random.choice('abcdefghijklmnopqrstuvwxyz')
print(f"Enter the LOWERCASE letter: {correct}")
else: # uppercase
correct = random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
print(f"Enter the UPPERCASE letter: {correct}")
answer = input("Your answer: ").strip()
if answer == correct:
score += 1
print("Correct!")
else:
print(f"Wrong! Correct answer was: {correct}")
print()
print(f"Test complete! Score: {score}/{questions}\n")
def main():
print("Welcome to Learning Bot! Type 'exit' anytime to quit.\n")
while True:
print("1. Learn numbers 1-10")
print("2. Learn lowercase letters a-z")
print("3. Learn uppercase letters A-Z")
print("4. Take a test")
print("5. Exit")
choice = input("\nChoose an option (1-5): ").strip().lower()
if choice == 'exit' or choice == '5':
print("Goodbye!")
break
if choice == '1':
learn_numbers()
elif choice == '2':
learn_lowercase()
elif choice == '3':
learn_uppercase()
elif choice == '4':
print("\nTest Categories:")
print("1. Numbers")
print("2. Lowercase letters")
print("3. Uppercase letters")
test_choice = input("Choose test category (1-3): ").strip().lower()
if test_choice == '1':
run_test('numbers')
elif test_choice == '2':
run_test('lowercase')
elif test_choice == '3':
run_test('uppercase')
else:
print("Invalid choice! Please try again.\n")
else:
print("Invalid choice! Please try again.\n")
if _name_ == "_main_":
main()
sample_emails = [
"Hey, just wanted to say hello!",
"Claim your FREE prize now! Click here!",
"Important meeting tomorrow at 3 PM",
"Limited time OFFER - 50% discount!",
"Your package has been delivered"
]
spam_keywords = ["free", "offer", "win", "prize", "urgent", "click", "discount"]
def check_spam(email):
email_lower = email.lower()
for keyword in spam_keywords:
if keyword in email_lower:
return True
return False
print("=== Simple Spam Detector ===")
print("Checking 5 sample emails...\n")
for index, email in enumerate(sample_emails, 1):
result = "SPAM" if check_spam(email) else "Not spam"
print(f"Email {index}: {result}")
print(f"Content: {email}\n")
print("Spam check completed!")
def celsius_to_fahrenheit():
c = float(input("Enter temperature in Celsius: "))
f = (c * 9/5) + 32
print(f"{c}°C = {f:.2f}°F")
def celsius_to_kelvin():
c = float(input("Enter temperature in Celsius: "))
k = c + 273.15
print(f"{c}°C = {k:.2f}K")
def fahrenheit_to_celsius():
f = float(input("Enter temperature in Fahrenheit: "))
c = (f - 32) * 5/9
print(f"{f}°F = {c:.2f}°C")
def fahrenheit_to_kelvin():
f = float(input("Enter temperature in Fahrenheit: "))
k = (f - 32) * 5/9 + 273.15
print(f"{f}°F = {k:.2f}K")
def kg_to_grams():
kg = float(input("Enter weight in kilograms: "))
grams = kg * 1000
print(f"{kg} kg = {grams} grams")
def grams_to_kg():
grams = float(input("Enter weight in grams: "))
kg = grams / 1000
print(f"{grams} grams = {kg} kg")
def meters_to_cm():
m = float(input("Enter length in meters: "))
cm = m * 100
print(f"{m} meters = {cm} cm")
def cm_to_meters():
cm = float(input("Enter length in centimeters: "))
m = cm / 100
print(f"{cm} cm = {m} meters")
def liters_to_ml():
liters = float(input("Enter volume in liters: "))
ml = liters * 1000
print(f"{liters} liters = {ml} mL")
def ml_to_liters():
ml = float(input("Enter volume in milliliters: "))
liters = ml / 1000
print(f"{ml} mL = {liters} liters")
def km_to_miles():
km = float(input("Enter distance in kilometers: "))
miles = km * 0.621371
print(f"{km} km = {miles:.2f} miles")
def main():
while True:
print("\nUnit Converter Menu:")
print("1. Celsius to Fahrenheit")
print("2. Celsius to Kelvin")
print("3. Fahrenheit to Celsius")
print("4. Fahrenheit to Kelvin")
print("5. Kilograms to Grams")
print("6. Grams to Kilograms")
print("7. Meters to Centimeters")
print("8. Centimeters to Meters")
print("9. Liters to Milliliters")
print("10. Milliliters to Liters")
print("11. Kilometers to Miles")
print("12. Exit")
try:
choice = int(input("\nEnter your choice (1-12): "))
except ValueError:
print("Please enter a valid number!")
continue
if choice == 12:
print("Goodbye!")
break
conversions = {
1: celsius_to_fahrenheit,
2: celsius_to_kelvin,
3: fahrenheit_to_celsius,
4: fahrenheit_to_kelvin,
5: kg_to_grams,
6: grams_to_kg,
7: meters_to_cm,
8: cm_to_meters,
9: liters_to_ml,
10: ml_to_liters,
11: km_to_miles
}
if choice in conversions:
try:
conversions[choice]()
except ValueError:
print("Invalid input! Please enter numbers only.")
else:
print("Invalid choice! Please select 1-12.")
input("\nPress Enter to continue...")
if __name__ == "__main__":
main()
import numpy as np
def add_numbers():
nums = list(map(float, input("Enter numbers to add (space-separated): ").split()))
print(f"Result: {np.sum(nums)}")
def subtract_numbers():
a, b = map(float, input("Enter two numbers (a b): ").split())
print(f"Result: {a - b}")
def multiply_numbers():
nums = list(map(float, input("Enter numbers to multiply (space-separated): ").split()))
print(f"Result: {np.prod(nums)}")
def divide_numbers():
a, b = map(float, input("Enter two numbers (a b): ").split())
print(f"Result: {a / b}" if b != 0 else "Error: Division by zero!")
def power_function():
a, b = map(float, input("Enter base and exponent (a b): ").split())
print(f"Result: {np.power(a, b)}")
def square_root():
num = float(input("Enter number: "))
print(f"Result: {np.sqrt(num)}")
def trigonometric_function():
func = input("Choose function (sin/cos/tan): ").lower()
angle = np.radians(float(input("Enter angle in degrees: ")))
operations = {
'sin': np.sin,
'cos': np.cos,
'tan': np.tan
}
if func in operations:
print(f"Result: {operations[func](angle):.4f}")
else:
print("Invalid function!")
def log_function():
base = input("Choose base (e/10): ").lower()
num = float(input("Enter number: "))
if base == 'e':
print(f"Result: {np.log(num):.4f}")
elif base == '10':
print(f"Result: {np.log10(num):.4f}")
else:
print("Invalid base!")
def matrix_operations():
print("\nMatrix Operations:")
print("1. Add matrices")
print("2. Multiply matrices")
print("3. Determinant")
print("4. Inverse")
choice = input("Select operation (1-4): ")
def get_matrix():
rows = int(input("Number of rows: "))
return np.array([list(map(float, input().split()))
for _ in range(rows)])
try:
if choice == '1':
print("Enter first matrix:")
mat1 = get_matrix()
print("Enter second matrix:")
mat2 = get_matrix()
print("Result:\n", np.add(mat1, mat2))
elif choice == '2':
print("Enter first matrix:")
mat1 = get_matrix()
print("Enter second matrix:")
mat2 = get_matrix()
print("Result:\n", np.matmul(mat1, mat2))
elif choice == '3':
mat = get_matrix()
print("Determinant:", np.linalg.det(mat))
elif choice == '4':
mat = get_matrix()
print("Inverse:\n", np.linalg.inv(mat))
else:
print("Invalid choice!")
except Exception as e:
print(f"Error: {str(e)}")
def statistics():
data = list(map(float, input("Enter numbers (space-separated): ").split()))
print(f"Mean: {np.mean(data):.2f}")
print(f"Median: {np.median(data):.2f}")
print(f"Standard Deviation: {np.std(data):.2f}")
print(f"Variance: {np.var(data):.2f}")
def show_menu():
print("\nScientific Calculator")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Power")
print("6. Square Root")
print("7. Trigonometric Functions")
print("8. Logarithms")
print("9. Matrix Operations")
print("10. Statistics")
print("11. Exit")
def main():
operations = {
'1': add_numbers,
'2': subtract_numbers,
'3': multiply_numbers,
'4': divide_numbers,
'5': power_function,
'6': square_root,
'7': trigonometric_function,
'8': log_function,
'9': matrix_operations,
'10': statistics
}
while True:
show_menu()
choice = input("\nSelect operation (1-11): ")
if choice == '11':
print("Goodbye!")
break
if choice in operations:
try:
operations[choice]()
except Exception as e:
print(f"Error: {str(e)}")
else:
print("Invalid choice!")
input("\nPress Enter to continue...")
if __name__ == "__main__":
main()
import time
import os
# Traffic light sequence with durations (in seconds)
LIGHT_SEQUENCE = [
("GREEN", 8),
("YELLOW", 3),
("RED", 10)
]
def clear_screen():
"""Clear the terminal screen"""
os.system('cls' if os.name == 'nt' else 'clear')
def display_light(color, remaining_time):
"""Display the current traffic light with countdown"""
clear_screen()
print("\n" + "="*30)
print(f"AI Traffic Light System\n")
print(f" {'⬤' if color == 'RED' else '◯'} RED")
print(f" {'⬤' if color == 'YELLOW' else '◯'} YELLOW")
print(f" {'⬤' if color == 'GREEN' else '◯'} GREEN")
print("\n" + "="*30)
print(f"Time remaining: {remaining_time} seconds\n")
def traffic_light_ai():
"""AI-controlled traffic light sequence"""
try:
while True:
for color, duration in LIGHT_SEQUENCE:
for remaining in range(duration, 0, -1):
display_light(color, remaining)
time.sleep(1)
except KeyboardInterrupt:
print("\nAI traffic system shut down")
if __name__ == "__main__":
traffic_light_ai()
def parse_number(input_str):
"""Parse user input into int, float, or complex number"""
input_str = input_str.strip().lower().replace('i', 'j')
try:
return int(input_str)
except ValueError:
try:
return float(input_str)
except ValueError:
try:
return complex(input_str)
except ValueError:
return None
def is_even(num):
"""Check if a number is even (works for integers and whole float numbers)"""
if isinstance(num, complex):
return 'N/A'
if isinstance(num, float) and not num.is_integer():
return 'N/A'
n = int(num) if isinstance(num, float) else num
return 'Yes' if isinstance(n, int) and n % 2 == 0 else 'No'
def is_odd(num):
"""Check if a number is odd"""
even = is_even(num)
return 'No' if even == 'Yes' else 'Yes' if even == 'No' else 'N/A'
def is_positive(num):
"""Check if a number is positive (real numbers only)"""
if isinstance(num, complex):
return 'N/A'
return 'Yes' if num > 0 else 'No'
def is_negative(num):
"""Check if a number is negative (real numbers only)"""
if isinstance(num, complex):
return 'N/A'
return 'Yes' if num < 0 else 'No'
def is_zero(num):
"""Check if a number is zero"""
if isinstance(num, complex):
return 'Yes' if num.real == 0 and num.imag == 0 else 'No'
return 'Yes' if num == 0 else 'No'
def is_prime(num):
"""Check if a number is prime (natural numbers > 1 only)"""
if isinstance(num, complex):
return 'N/A'
if isinstance(num, float) and not num.is_integer():
return 'N/A'
n = int(num) if isinstance(num, float) else num
if not isinstance(n, int) or n <= 1:
return 'N/A'
if n == 2:
return 'Yes'
if n % 2 == 0:
return 'No'
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return 'No'
return 'Yes'
def is_composite(num):
"""Check if a number is composite (natural numbers > 1 only)"""
prime = is_prime(num)
if prime == 'N/A' or num == 1:
return 'N/A'
return 'Yes' if prime == 'No' else 'No'
def is_complex(num):
"""Check if a number is complex"""
return 'Yes' if isinstance(num, complex) else 'No'
def is_palindrome(num):
"""Check if a number is a palindrome (non-negative integers only)"""
if isinstance(num, complex):
return 'N/A'
if isinstance(num, float) and not num.is_integer():
return 'N/A'
n = int(num) if isinstance(num, float) else num
if not isinstance(n, int) or n < 0:
return 'N/A'
s = str(n)
return 'Yes' if s == s[::-1] else 'No'
def is_armstrong(num):
"""Check if a number is an Armstrong number (non-negative integers only)"""
if isinstance(num, complex):
return 'N/A'
if isinstance(num, float) and not num.is_integer():
return 'N/A'
n = int(num) if isinstance(num, float) else num
if not isinstance(n, int) or n < 0:
return 'N/A'
order = len(str(n))
temp = n
total = 0
while temp > 0:
digit = temp % 10
total += digit ** order
temp //= 10
return 'Yes' if total == n else 'No'
def main():
print("Number Property Analyzer")
print("Enter any number (integer, float, complex). Type 'q' to quit.")
while True:
user_input = input("\nEnter a number: ").strip()
if user_input.lower() == 'q':
print("Goodbye!")
break
num = parse_number(user_input)
if num is None:
print("Invalid number! Try again.")
continue
print("\n=== Analysis Results ===")
print(f"Number: {num}")
print(f"1. Even: {is_even(num)}")
print(f"2. Odd: {is_odd(num)}")
print(f"3. Positive: {is_positive(num)}")
print(f"4. Negative: {is_negative(num)}")
print(f"5. Zero: {is_zero(num)}")
print(f"6. Prime: {is_prime(num)}")
print(f"7. Composite: {is_composite(num)}")
print(f"8. Complex: {is_complex(num)}")
print(f"9. Palindrome: {is_palindrome(num)}")
print(f"10. Armstrong: {is_armstrong(num)}")
if __name__ == "__main__":
main()
#2import speech_recognition as sr
import pyttsx3
from gtts import gTTS
import os
import time
from playsound import playsound
def speech_to_text():
"""Convert speech from microphone to text"""
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Listening... (speak now)")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
print("Recognizing...")
text = recognizer.recognize_google(audio)
print(f"You said: {text}")
return text
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError:
print("Could not request results; check internet connection")
return ""
def text_to_speech_pyttsx3(text):
"""Convert text to speech using pyttsx3 (offline)"""
engine = pyttsx3.init()
engine.setProperty('rate', 150) # Speed of speech
engine.setProperty('volume', 0.9) # Volume (0.0 to 1.0)
engine.say(text)
engine.runAndWait()
def text_to_speech_gtts(text, lang='en'):
"""Convert text to speech using gTTS (requires internet)"""
tts = gTTS(text=text, lang=lang, slow=False)
filename = "temp_audio.mp3"
tts.save(filename)
playsound(filename)
os.remove(filename)
def main():
while True:
print("\nVoice Assistant Menu:")
print("1. Speech to Text")
print("2. Text to Speech (Offline)")
print("3. Text to Speech (Online)")
print("4. Exit")
choice = input("Choose option (1-4): ")
if choice == '4':
print("Goodbye!")
break
if choice == '1':
result = speech_to_text()
if result:
print(f"Recognized text: {result}")
elif choice == '2':
text = input("Enter text to speak: ")
text_to_speech_pyttsx3(text)
elif choice == '3':
text = input("Enter text to speak: ")
text_to_speech_gtts(text)
else:
print("Invalid choice! Try again.")
time.sleep(1)
if __name__ == "__main__":
# Install required packages first:
# pip install SpeechRecognition pyttsx3 gTTS playsound pyaudio
main()