back

Py Home Work

Python Practice Problems

If Else

  1. Compute Indian income tax rate for given annual salary 1 a. [4-8 -> 5%, 8-12 -> 10%, 12-16 -> 15%, 16-20 -> 20%, 20-24 -> 25%, above 24 -> 30%]
  2. Given a metal name (gold, silver, platinum), print their price
  3. Given a number, if odd double it (2x), if even return same. 3 -> 6, 4 -> 4
  4. Given two numbers find min
  5. Given two number find max
  6. Given number, print day of the week 1 -> Monday 7 -> Sunday
  7. Given exam scores ex [50, 23, 36, 45, 30] check if user failed or passed an exam. Pass score 36
  8. Given an number, print whether given number is positive, negative or zero
  9. Given room temperature, print whether it is Normal, Hot or Cold
    1. 21-24 Normal
    2. Above 24 Hot
    3. Below 21 Cold
  10. Given age check if user can vote. min age 18
  11. Given age check if user can drive min age 18
  12. Given mark check if user fail. pass mark 36
  13. Given mark check if user scored centum (100)
  14. Given body temperature check if user has fever (more than 100)
  15. Given user name, password print ‘success’ if they match ‘admin’, ‘1234’
  16. Given a number, print ‘positive’, ‘negative’ or ‘zero’
  17. Check if given number is divisible by 3 and 5
  18. Check if a candidate is eligible to appear for a role with age limit 21-32
  19. Given a day check if it falls on week end (sat/sun)
  20. Given a color name check if it is primary color (Red/Green/Blue)

String

  1. Find file type image.png, file.pdf, file.docx
  2. Find position of given word
  3. Reverse string
  4. Parse csv “”

Loop

  1. Find total of numbers from 1 … N
  2. Print each character in a string
  3. Count number of vowels (a,e,i,o,u) from given string
  4. Reverse given string using while loop
  5. Extract only numbers from given string a. ex: “abc122dkjf834”
  6. Find total from csv data: a. ex: “John,45,23,76,87,98”
  7. Print 1, 2, 3 … 10
  8. Print 2, 4 ,6 … 20
  9. Print Table given a number a. Ex: 2 -> 1x2, 2x2, 3x2 … 10x2
  10. Find all odd numbers until given number a. Ex: 10 -> 1, 3, 5, 7, 9
  11. Find all numbers divisible by 3 until given number a. Ex: 10 -> 3, 6, 9
  12. Find all numbers divisible by 3 and 5 until given number a. Ex: 50 -> 15, 30, 45
  13. Sum of natural numbers until given number a. Ex: input: 4 -> 1 + 2 + 3 + 4 -> 10
  14. Find factorial of given number a. Ex: input 5 -> 5 * 4 * 3 * 2 * 1 -> 120

Revision:

  1. Reverse a string using index:
    data = "hello world"
  
    start = 0
    stop = len(data)
    step = 1

    for i in range(0, len(data), 1):
        print(data[i])
  1. Sum of square of even numbers upto N
  2. Find total, pass / fail, average, rank
     data = "John,30,40,50,60\nDave,10,20,30,45,50\nAdam,40,95,87,67,50"