Question:
Write a Python program to guess a random number between 1 and 5.
Program:
import random
num = [Link](1,5)
guess = int(input("Guess a number (1-5): "))
if guess == num:
print("You Win 🎉")
else:
print("You Lose 😢, Number was:", num)
Even or Odd Checker
Question:
Write a Python program to check whether a number is even or odd.
Program:
n = int(input("Enter a number: "))
if n % 2 == 0:
print("Even Number")
else:
print("Odd Number")
Password Length Fun
Question:
Check whether a password is weak or strong based on length.
Program:
pwd = input("Enter password: ")
if len(pwd) < 6:
print("Weak Password 😴")
else:
print("Strong Password 💪")
Name Reverse Game
Question:
Write a program to reverse a string.
Program:
name = input("Enter your name: ")
print("Reversed Name:", name[::-1])
Vowel Counter
Question:
Count number of vowels in a string.
Program:
text = input("Enter text: ")
count = 0
for ch in text:
if ch in "aeiouAEIOU":
count += 1
print("Vowels:", count)
Simple Calculator
Question:
Perform addition or multiplication using menu.
Program:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("[Link] [Link]")
ch = int(input("Choice: "))
if ch == 1:
print("Sum =", a + b)
elif ch == 2:
print("Product =", a * b)
List Fun – Shopping Cart
Question:
Add items to a shopping cart and display them.
Program:
cart = []
[Link]("Pen")
[Link]("Book")
[Link]("Laptop")
print("Shopping Cart:", cart)
Output:
Shopping Cart: ['Pen', 'Book', 'Laptop']
Question:
Create a simple rule-based chatbot.
Program:
msg = input("You: ").lower()
if "hi" in msg:
print("Bot: Hello 🤖")
elif "bye" in msg:
print("Bot: Bye 👋")
else:
print("Bot: Learning...")
Output:
You: hi
Bot: Hello 🤖
Question:
Create a chatbot that performs calculations.
Program:
msg = input("You: ").lower()
if "add" in msg:
a = int(input("Enter a: "))
b = int(input("Enter b: "))
print("Bot:", a + b)
elif "multiply" in msg:
a = int(input("Enter a: "))
b = int(input("Enter b: "))
print("Bot:", a * b)
else:
print("Bot: I can add or multiply numbers")