back
Py Home Work
Python Practice Problems
If Else
- 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%]
- Given a metal name (gold, silver, platinum), print their price
- Given a number, if odd double it (2x), if even return same. 3 -> 6, 4 -> 4
- Given two numbers find min
- Given two number find max
- Given number, print day of the week 1 -> Monday 7 -> Sunday
- Given exam scores ex [50, 23, 36, 45, 30] check if user failed or passed an exam. Pass score 36
- Given an number, print whether given number is positive, negative or zero
- Given room temperature, print whether it is Normal, Hot or Cold
- 21-24 Normal
- Above 24 Hot
- Below 21 Cold
- Given age check if user can vote. min age 18
- Given age check if user can drive min age 18
- Given mark check if user fail. pass mark 36
- Given mark check if user scored centum (100)
- Given body temperature check if user has fever (more than 100)
- Given user name, password print ‘success’ if they match ‘admin’, ‘1234’
- Given a number, print ‘positive’, ‘negative’ or ‘zero’
- Check if given number is divisible by 3 and 5
- Check if a candidate is eligible to appear for a role with age limit 21-32
- Given a day check if it falls on week end (sat/sun)
- Given a color name check if it is primary color (Red/Green/Blue)
String
- Find file type image.png, file.pdf, file.docx
- Find position of given word
- Reverse string
- Parse csv “”
Loop
- Find total of numbers from 1 … N
- Print each character in a string
- Count number of vowels (a,e,i,o,u) from given string
- Reverse given string using while loop
- Extract only numbers from given string a. ex: “abc122dkjf834”
- Find total from csv data: a. ex: “John,45,23,76,87,98”
- Print 1, 2, 3 … 10
- Print 2, 4 ,6 … 20
- Print Table given a number a. Ex: 2 -> 1x2, 2x2, 3x2 … 10x2
- Find all odd numbers until given number a. Ex: 10 -> 1, 3, 5, 7, 9
- Find all numbers divisible by 3 until given number a. Ex: 10 -> 3, 6, 9
- Find all numbers divisible by 3 and 5 until given number a. Ex: 50 -> 15, 30, 45
- Sum of natural numbers until given number a. Ex: input: 4 -> 1 + 2 + 3 + 4 -> 10
- Find factorial of given number a. Ex: input 5 -> 5 * 4 * 3 * 2 * 1 -> 120
Revision:
- 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])
- Sum of square of even numbers upto N
- Find total, pass / fail, average, rank
data = "John,30,40,50,60\nDave,10,20,30,45,50\nAdam,40,95,87,67,50"