Practice Set 2
Practice Set 2
1. Write a program that inputs the user's name and prints a greeting message like "Hello,
[Name]!".
2. Write a program that inputs two numbers and prints their sum.
3. Write a program that asks the user for their age and prints "You are [age] years old."
4. Write a program that takes a sentence as input and prints it in uppercase.
5. Write a program that takes a number as input and prints its square.
2. Operators
Arithmetic Operators
1. Write a program to add, subtract, multiply, and divide two numbers.
2. Write a program to calculate the remainder of two numbers using the modulus operator.
3. Write a program to calculate the power of a number (e.g., 2^3).
4. Write a program to find the average of three numbers.
5. Write a program to swap two numbers without using a temporary variable.
Relational Operators
1. Write a program to compare two numbers and print which one is greater.
2. Write a program to check if two numbers are equal.
3. Write a program to check if a number is greater than or equal to 10.
4. Write a program to check if a number is less than 100.
5. Write a program to check if two strings are the same.
Assignment Operators
1. Write a program to increment a number by 5 using the `+=` operator.
2. Write a program to decrement a number by 3 using the `-=` operator.
3. Write a program to multiply a number by 2 using the `=` operator.
4. Write a program to divide a number by 4 using the `/=` operator.
5. Write a program to find the remainder of a number divided by 7 using the `%=` operator.
Logical Operators
1. Write a program to check if a number is between 10 and 20 using `and`.
2. Write a program to check if a number is either less than 5 or greater than 50 using `or`.
3. Write a program to check if a number is not equal to 0 using `not`.
4. Write a program to check if a user's age is either 18 or 21.
5. Write a program to check if a string is empty or not.
Bitwise Operators
1. Write a program to perform a bitwise AND operation on two numbers.
2. Write a program to perform a bitwise OR operation on two numbers.
3. Write a program to perform a bitwise NOT operation on a number.
4. Write a program to perform a bitwise XOR operation on two numbers.
5. Write a program to shift a number left by 2 bits.
Membership Operators
1. Write a program to check if a character is present in a string using `in`.
2. Write a program to check if a number is not in a list using `not in`.
3. Write a program to check if a key exists in a dictionary.
4. Write a program to check if a substring is present in a string.
5. Write a program to check if a value is not in a tuple.
Identity Operators
1. Write a program to check if two variables point to the same object using `is`.
2. Write a program to check if two lists are different objects using `is not`.
3. Write a program to compare two integers using `is`.
4. Write a program to compare two strings using `is not`.
5. Write a program to check if a variable is `None` using `is`.
Conditional Statements
1. Write a program to check if a number is positive, negative, or zero using `if-else`.
2. Write a program to check if a number is even or odd using `if-else`.
3. Write a program to find the largest of three numbers using `if-elif-else`.
4. Write a program to check if a year is a leap year using nested `if`.
5. Write a program to assign grades (A, B, C, D, F) based on a student's score using
`if-elif-else`.
Loops in Python
1. Write a program to print numbers from 1 to 10 using a `for` loop.
2. Write a program to print the multiplication table of a number using a `while` loop.
3. Write a program to print the elements of a list using a `for` loop.
4. Write a program to find the sum of all numbers from 1 to 100 using a `for` loop.
5. Write a program to print a pattern (e.g., a pyramid) using nested loops.
Loop Manipulation Statements
1. Write a program to print numbers from 1 to 10 but skip 5 using `continue`.
2. Write a program to exit a loop if a number equals 7 using `break`.
3. Write a program to print "Loop completed" after a loop finishes using `else`.
4. Write a program to use `pass` as a placeholder in an empty loop.
5. Write a program to print numbers from 1 to 10 but stop if the number is greater than 5 using
`break`.