Logical, Comparison and Special Operator
Logical, Comparison and Special Operator
Write a Python program that prompts the user to enter their age. If the age
entered is between 18 and 65 (inclusive), print "You are eligible for the job",
otherwise print "You are not eligible for the job".
Temperature Check:
Write a Python program that prompts the user to input the current temperature
in Celsius. If the temperature is above 30 degrees Celsius or below 0 degrees
Celsius, print "Extreme weather conditions!", otherwise print "Enjoy the
weather!".
Discount Calculator:
Create a Python program that calculates the discounted price of an item. If the
item price is above $100 and the customer is a prime member, apply a
discount of 10%. Otherwise, apply a discount of 5%.
Login System:
Develop a Python program that asks the user to enter their username and
password. If the username is "admin" and the password is "password123",
print "Login successful", otherwise print "Invalid credentials".
Write a Python program that prompts the user to input a year. Check if the
entered year is a leap year. If it is, print "Leap year", otherwise print "Not a
leap year". (Hint: A leap year is divisible by 4 but not by 100 unless it is also
divisible by 400.)
Traffic Light Simulation:
Implement a Python program that simulates a traffic light. The program should
prompt the user to input the current color of the traffic light. If the color is "red",
print "Stop". If it's "yellow", print "Proceed with caution". If it's "green", print
"Go".
Create a Python function that takes three integers as inputs representing the
lengths of the sides of a triangle. The function should return a string indicating
the type of triangle: "equilateral", "isosceles", "scalene", or "not a triangle".
Divisibility Checker:
Write a Python program that prompts the user to input a number. Check if the
number is divisible by both 2 and 3. If it is, print "The number is divisible by 2
and 3", otherwise print "The number is not divisible by 2 and 3".
Develop a Python program that checks if the player has lost the game. The
game is lost if the player's health is less than or equal to 0, or if the time runs
out. If either condition is true, print "Game over", otherwise print "Keep
playing".
Grade Classification:
Write a Python program that prompts the user to input their exam score.
Based on the score, print "A" if the score is greater than or equal to 90, "B" if it's
between 80 and 89, "C" if it's between 70 and 79, "D" if it's between 60 and 69,
and "F" if it's below 60.
Create a Python program that asks the user to input their age. Based on the
age provided, print "Child" if the age is less than 13, "Teenager" if it's between
13 and 19, "Adult" if it's between 20 and 64, and "Senior" if it's 65 or older.
BMI Calculator:
Develop a Python program that takes the user's weight (in kilograms) and
height (in meters) as input and calculates their BMI (Body Mass Index). Then,
classify the BMI using the following criteria:
○ BMI < 18.5: "Underweight"
○ 18.5 <= BMI < 25: "Normal weight"
○ 25 <= BMI < 30: "Overweight"
○ BMI >= 30: "Obese"
Time Comparison:
Write a Python program that prompts the user to input two times in the format
"HH:MM" (24-hour format). Compare the two times and print "Time 1 is
earlier" if the first time is earlier than the second, "Time 2 is earlier" if the
second time is earlier, and "Both times are the same" if they are equal.
Create a Python program that compares the prices of two products. Prompt
the user to input the prices of two products and print the product with the
lower price along with the statement "is cheaper".
Temperature Comparison:
Develop a Python program that prompts the user to input two temperatures in
Celsius. Compare the temperatures and print "Temperature 1 is higher" if the
first temperature is higher than the second, "Temperature 2 is higher" if the
second temperature is higher, and "Both temperatures are the same" if they
are equal.
Write a Python program that compares the scores of two students in an exam.
Prompt the user to input the scores of two students and print "Student 1
performed better" if the score of the first student is higher, "Student 2
performed better" if the score of the second student is higher, and "Both
students performed equally" if their scores are the same.
Create a Python program that asks the user to input their age and checks if
they are eligible to vote. If the age is 18 or above, print "You are eligible to
vote", otherwise print "You are not eligible to vote".
Guessing Game:
Write a Python program that generates a random number between 1 and 100.
Prompt the user to guess the number. Compare the user's guess with the
generated number and print "Too high" if the guess is greater, "Too low" if it's
smaller, and "Congratulations! You guessed it!" if they guess correctly.
Bitwise OR Operation:
Write a Python program that uses bitwise AND operation to check if a given
integer provided by the user is even or odd. Prompt the user to input an
integer and print whether it's even or odd.
Develop a Python program that toggles (flips) the bit at a specific position in
an integer provided by the user. Prompt the user to input an integer and the
position of the bit to toggle. Print the result after toggling the bit.
Check Power of 2:
Create a Python program that uses bitwise AND operation to check if a given
integer provided by the user is a power of 2. Prompt the user to input an
integer and print whether it's a power of 2 or not.
Write a Python program that swaps the values of two integers provided by the
user using bitwise XOR operation. Prompt the user to input two integers and
print the swapped values.
Object Comparison:
Write a Python program that creates two lists with the same elements. Use
the identity operator is to check if both lists refer to the same object in
memory. Print the result.
Variable Comparison:
Create two variables x and y and assign the same integer value to both. Use
the identity operator is to check if both variables refer to the same object in
memory. Print the result.
String Comparison:
Declare two string variables str1 and str2 with the same content. Use the
identity operator is to check if both strings refer to the same object in
memory. Print the result.
Write a Python program that creates two empty lists using different methods
(e.g., list() constructor and []). Use the identity operator is to check if both
lists refer to the same object in memory. Print the result.
None Comparison:
Create a variable x and assign None to it. Use the identity operator is to check
if x is None. Print the result.
Object Reassignment:
Write a Python program that creates a list list1 and assigns it to another
variable list2. Then, modify list1 by appending an element. Use the identity
operator is to check if list1 and list2 still refer to the same object in
memory. Print the result.
Declare two variables a and b and assign the same integer value to both. Use
the identity operator is to check if a and b refer to the same object in memory.
Print the result.
Dictionary Comparison:
Write a Python program that creates two dictionaries with the same key-value
pairs. Use the identity operator is to check if both dictionaries refer to the
same object in memory. Print the result.
Define a function create_list() that returns a list object. Call this function
twice and use the identity operator is to check if the returned lists are the
same objects in memory. Print the result.
List Membership:
Write a Python program that prompts the user to enter a number. Check if the
number is present in a predefined list of numbers using the in operator. Print
a message indicating whether the number is found in the list or not.
String Membership:
Create a Python program that asks the user to input a character. Check if the
character is present in a given string using the in operator. Print a message
indicating whether the character is found in the string or not.
Tuple Membership:
Define a tuple containing the names of some fruits. Prompt the user to enter
the name of a fruit. Check if the entered fruit name is present in the tuple
using the in operator. Print a message indicating whether the fruit is found in
the tuple or not.
Dictionary Membership:
Write a Python program that defines a dictionary containing some words and
their corresponding meanings. Prompt the user to input a word. Check if the
entered word is present in the dictionary keys using the in operator. Print a
message indicating whether the word is found in the dictionary or not.
Create two strings containing words or phrases. Use the in operator to check
if the second string is a substring of the first string. If it is, concatenate the
two strings and print the result; otherwise, print a message indicating that no
concatenation is performed.
Set Membership:
Define a set containing some unique values. Prompt the user to input a value.
Check if the entered value is present in the set using the in operator. Print a
message indicating whether the value is found in the set or not.
Create a list containing several strings. Prompt the user to input a string. Use
the in operator to check if the entered string is present in the list. Print a
message indicating whether the string is found in the list or not.
Define a string containing a sentence. Prompt the user to input a word. Use
the in operator to check if the entered word is present in the sentence
(ignoring case). If it is, slice the sentence to include only the portion before
the word and print the result; otherwise, print a message indicating that the
word is not found.