Chapter 4: User Input and Operators Assignments

Test your understanding of user input and Python operators with the following exercises.

Basic (10 Questions)

  1. Write a program to take your name and age as input and display them using print().
  2. Accept two numbers from the user and print their sum, difference, product, and quotient.
  3. Check if a given number is even or odd using the modulus operator (%).
  4. Take an integer input and check if it is positive, negative, or zero.
  5. Use command line arguments to read two numbers and print their average.
  6. Demonstrate the use of // and ** operators with sample values.
  7. Take a string input and use the in operator to check for a specific character.
  8. Take a number input and check if it lies between 10 and 100 using comparison operators.
  9. Use is and is not to compare two variables.
  10. Print the result of different bitwise operators (&, |, ^, ~).

Intermediate (10 Questions)

  1. Write a program to accept two numbers and swap them without using a third variable.
  2. Use and, or, not to evaluate logical expressions and print results.
  3. Check if a character is a vowel using membership operators.
  4. Take three numbers as input and find the greatest using comparison and logical operators.
  5. Use bitwise shift operators (<<, >>) on a number and explain the result.
  6. Write a Python script that accepts command-line arguments and checks if they are valid integers.
  7. Check whether two user inputs refer to the same object using is.
  8. Build a calculator that supports +, -, *, / using if-else and user input.
  9. Accept a float and round it to the nearest integer.
  10. Take a string and number input, and print the string repeated that many times.

Advanced (10 Questions)

  1. Implement a mini CLI-based program that takes two numbers and an operator as arguments and performs the operation.
  2. Simulate a login system that accepts username and password input and checks if they match predefined values.
  3. Write a function that performs bitwise AND on a list of numbers taken as input.
  4. Use eval() to evaluate a user-provided arithmetic expression and display the result.
  5. Write a script to check if a number is divisible by both 3 and 5 using logical operators.
  6. Create a menu-driven CLI app that lets users choose between different mathematical operations.
  7. Take a number input and check whether it is a power of 2 using bitwise operations.
  8. Compare the identities of multiple variables and explain using id().
  9. Take five inputs and determine which of them are even using a single line expression with logical and arithmetic operators.
  10. Accept an expression from the user and identify all the operators used in it.