Test your understanding of user input and Python operators with the following exercises.
Basic (10 Questions)
- Write a program to take your name and age as input and display them using
print()
.
- Accept two numbers from the user and print their sum, difference, product, and quotient.
- Check if a given number is even or odd using the modulus operator (
%
).
- Take an integer input and check if it is positive, negative, or zero.
- Use command line arguments to read two numbers and print their average.
- Demonstrate the use of
//
and **
operators with sample values.
- Take a string input and use the
in
operator to check for a specific character.
- Take a number input and check if it lies between 10 and 100 using comparison operators.
- Use
is
and is not
to compare two variables.
- Print the result of different bitwise operators (
&
, |
, ^
, ~
).
Intermediate (10 Questions)
- Write a program to accept two numbers and swap them without using a third variable.
- Use
and
, or
, not
to evaluate logical expressions and print results.
- Check if a character is a vowel using membership operators.
- Take three numbers as input and find the greatest using comparison and logical operators.
- Use bitwise shift operators (
<<
, >>
) on a number and explain the result.
- Write a Python script that accepts command-line arguments and checks if they are valid integers.
- Check whether two user inputs refer to the same object using
is
.
- Build a calculator that supports +, -, *, / using if-else and user input.
- Accept a float and round it to the nearest integer.
- Take a string and number input, and print the string repeated that many times.
Advanced (10 Questions)
- Implement a mini CLI-based program that takes two numbers and an operator as arguments and performs the operation.
- Simulate a login system that accepts username and password input and checks if they match predefined values.
- Write a function that performs bitwise AND on a list of numbers taken as input.
- Use
eval()
to evaluate a user-provided arithmetic expression and display the result.
- Write a script to check if a number is divisible by both 3 and 5 using logical operators.
- Create a menu-driven CLI app that lets users choose between different mathematical operations.
- Take a number input and check whether it is a power of 2 using bitwise operations.
- Compare the identities of multiple variables and explain using
id()
.
- Take five inputs and determine which of them are even using a single line expression with logical and arithmetic operators.
- Accept an expression from the user and identify all the operators used in it.