0% found this document useful (0 votes)
3 views7 pages

Python Coding For Class 12

The document outlines a chatbot program that engages users in various activities such as quizzes, riddles, jokes, and motivational quotes. It includes functionalities for checking the time, day, weather, and opening applications or websites. Users can interact with the chatbot until they type 'exit' or 'bye' to end the conversation.

Uploaded by

tharun3791
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Python Coding For Class 12

The document outlines a chatbot program that engages users in various activities such as quizzes, riddles, jokes, and motivational quotes. It includes functionalities for checking the time, day, weather, and opening applications or websites. Users can interact with the chatbot until they type 'exit' or 'bye' to end the conversation.

Uploaded by

tharun3791
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import webbrowser

import os

import subprocess

from datetime import datetime

import random

print("Chatbot: Hello! I'm your extended chatbot. Type 'exit' anytime to end the chat.")

# Improved Quiz Questions

quiz_questions = [

{"question": "What is the capital city of Japan?", "answer": "tokyo"},

{"question": "Who discovered gravity when he saw a falling apple?", "answer": "newton"},

{"question": "What is the chemical symbol for gold?", "answer": "au"},

{"question": "Who is known as the 'King of Pop'?", "answer": "michael jackson"},

{"question": "Which planet is known as the Red Planet?", "answer": "mars"},

{"question": "In what year did humans first land on the moon?", "answer": "1969"},

{"question": "What is the largest ocean on Earth?", "answer": "pacific"},

{"question": "Who wrote 'Harry Potter'?", "answer": "jk rowling"},

{"question": "Which country is famous for the Eiffel Tower?", "answer": "france"},

{"question": "What sport is Serena Williams known for?", "answer": "tennis"},

{"question": "How many bones are there in the human body?", "answer": "206"},

{"question": "Which element has the atomic number 1?", "answer": "hydrogen"},

{"question": "What is the smallest country in the world?", "answer": "vatican city"},

{"question": "Who painted the ceiling of the Sistine Chapel?", "answer": "michelangelo"},

{"question": "What is the capital of Australia?", "answer": "canberra"},

{"question": "Which author wrote 'Pride and Prejudice'?", "answer": "jane austen"},

{"question": "What is the fastest bird in the world?", "answer": "peregrine falcon"},

{"question": "In which country is the Great Pyramid of Giza located?", "answer": "egypt"},

{"question": "What is the hardest natural substance on Earth?", "answer": "diamond"},

{"question": "Who was the first president of the United States?", "answer": "george washington"}]
# Fun riddles

riddles = [

{"riddle": "What has keys but can't open locks?", "answer": "piano"},

{"riddle": "What has branches, but no fruit, trunk or leaves?", "answer": "bank"},

{"riddle": "What comes once in a minute, twice in a moment, but never in a thousand years?",
"answer": "the letter 'm'"},

{"riddle": " I cannot talk, but I always reply when spoken to. What am I?", "answer": "echo"}]

user_input = ""

while user_input.lower() != "exit":

user_input = input("You: ").strip()

# Check if input is a math expression

try:

result = eval(user_input)

print(f"Chatbot: The result is {result}")

continue

except Exception:

pass # If eval fails, proceed with other responses

# Greetings

if "hello" in user_input.lower() or "hi" in user_input.lower():

print("Chatbot: Hi there! How can I assist you today?")

elif "how are you" in user_input.lower():

print("Chatbot: I’m just a program, so I’m always here to help! How about you?")

elif "who are you" in user_input.lower():

print("Chatbot: I'm your friendly assistant, here to chat and help you with tasks!")
# Quiz Feature

elif "quiz" in user_input.lower() or "ask me a question" in user_input.lower():

print("Chatbot: Great! Let’s start the quiz. Type 'stop quiz' anytime to end.")

[Link](quiz_questions) # Randomize questions

score = 0

for question in quiz_questions:

print(f"Chatbot: {question['question']}")

answer = input("You: ").strip().lower()

if answer == "stop quiz":

break

elif answer == question['answer']:

print("Chatbot: Correct!")

score += 1

else:

print(f"Chatbot: Oops! The correct answer is '{question['answer']}'.")

print(f"Chatbot: Quiz finished! Your final score is {score}/{len(quiz_questions)}.")

continue

# Time and Day

elif "time" in user_input.lower():

current_time = [Link]().strftime("%H:%M:%S")

print(f"Chatbot: The current time is {current_time}.")

elif "day" in user_input.lower():

current_day = [Link]().strftime("%A")

print(f"Chatbot: Today is {current_day}.")

# Jokes

elif "joke" in user_input.lower():

jokes = [
"Why don’t skeletons fight each other? Because they don’t have the guts!",

"Why did the scarecrow win an award? Because he was outstanding in his field!",

"Why don’t eggs tell jokes? They’d crack each other up!"]

print(f"Chatbot: {[Link](jokes)}")

# Weather Report

elif "weather" in user_input.lower():

print("Chatbot: Sure! Please tell me the name of the city.")

city = input("You: ").strip()

print(f"Chatbot: Searching for the weather in {city}...")

[Link](f"[Link]

# Motivational Quotes

elif "motivate me" in user_input.lower() or "quote" in user_input.lower():

quotes = [

"Believe you can and you’re halfway there. – Theodore Roosevelt",

"It does not matter how slowly you go as long as you do not stop. – Confucius",

"Your limitation—it’s only your imagination. – Anonymous",

"Push yourself, because no one else is going to do it for you. – Anonymous"]

print(f"Chatbot: {[Link](quotes)}")

# Fun Facts

elif "fact" in user_input.lower() or "something interesting" in user_input.lower():

facts = [

"Did you know that octopuses have three hearts?",

"Bananas are berries, but strawberries are not!",

"Honey never spoils—it’s edible for thousands of years!",

"A group of flamingos is called a 'flamboyance.'"]


print(f"Chatbot: {[Link](facts)}")

# Web Browser Search

elif "search" in user_input.lower():

print("Chatbot: What would you like to search for?")

query = input("You: ").strip()

[Link](f"[Link]

print(f"Chatbot: I’ve searched for '{query}' on Google.")

# Open Website Functionality

elif "open website" in user_input.lower():

print("Chatbot: Please provide the website URL (e.g., [Link]):")

website = input("You: ").strip()

if not [Link]("http"):

website = "[Link] + website

[Link](website)

print(f"Chatbot: I’ve opened {website} in your browser.")

# Riddle Challenge

elif "riddle" in user_input.lower():

print("Chatbot: I love riddles! Let me ask you one.")

riddle = [Link](riddles)

print(f"Chatbot: {riddle['riddle']}")

answer = input("You: ").strip().lower()

if answer == riddle["answer"]:

print("Chatbot: Correct! Well done!")

else:

print(f"Chatbot: Oops! The correct answer is '{riddle['answer']}'.")

# Open Apps Functionality

# Check if the user wants to open an app

if "open app" in user_input.lower():


print("Chatbot: Which app would you like to open? (e.g., Notepad, Chrome, VLC, Word, Excel,
etc.)")

app_name = input("You: ").strip().lower()

if [Link] == "nt": # Windows-specific

apps = {

"notepad": "[Link]",

"chrome": "[Link]",

"calculator": "[Link]",

"word": "[Link]",

"excel": "[Link]",

"powerpoint": "[Link]",

"spotify": "[Link]",

"vlc": "[Link]",

"paint": "[Link]",

"edge": "[Link]",

app_path = [Link](app_name)

if app_path:

try:

[Link](app_path)

print(f"Chatbot: Opening {app_name.capitalize()}...")

except Exception:

print(f"Chatbot: Unable to open {app_name.capitalize()}. Please make sure it is


installed.")

else:

print(f"Chatbot: Sorry, I don’t recognize the app '{app_name}'.")

else: # macOS/Linux-specific

apps = {

"safari": "safari",

"chrome": "google-chrome",

"calculator": "gnome-calculator",

"vlc": "vlc",
"spotify": "spotify",

"word": "libreoffice --writer",

"excel": "libreoffice --calc",

"powerpoint": "libreoffice --impress",

"notepad": "gedit",

"paint": "gimp",

app_command = [Link](app_name)

if app_command:

try:

[Link](app_command.split(), check=True)

print(f"Chatbot: Opening {app_name.capitalize()}...")

except Exception:

print(f"Chatbot: Unable to open {app_name.capitalize()}. Please make sure it is


installed.")

else:

print(f"Chatbot: Sorry, I don’t recognize the app '{app_name}'.")

continue

elif user_input.lower() == "bye":

print("Chatbot: Goodbye")

break

You might also like