Your one stop guide to polish your Python skills.
Green means easy. Orange means challenging. Red is a bit difficult. The difficulty of these questions are with reference to the course taught in class and takes into account the average performance of students in assignments and quizzes. Some might feel the reds == easy for them while some students might feel orange == difficult.
CHAPTER 1: BASICS
- Enter an input from user asking their age and name. Print it Note: You may save it in a variable or just print it directly.
- Perform the following tasks:
- Take an input(a decimal/float number) from the user, save it in a variable (let’s say r2d2). Do not type cast yet.
- Print the type of variable r2d2 (without any conversion or type casting)
- Convert/type cast it to float and reprint its data type.
- Print the following line using a single print statement. Hint: use escape operator
- “Hello Mr. O’Brien, It’s a pleasure to meet you”, said the manager.
- Take three integer input from the user. These input are the scores they received in a test(out of 20). Print the total scores, average and names of the subjects in a single line using three different print statements. Hint: How do you stitch multiple prints?
- Take age from the user and save it in a variable. Print the number of years required for that user to reach the age of 50.
- Take two numbers from the user. Perform an operation involving two arithmetic operations. It can be any arithmetic operation. DO NOT use logical or comparator operators.
CHAPTER 2: CONDITIONS
- Take length and breadth of a rectangle and check if it is a square or not.
- Take age as user input from 3 users. Find the youngest and oldest among them.
- Ask user for a year and find if it is a leap year or not.
- Write a program to accept cost price of a car and display road tax to be paid according to following table.
- Price of the car and equivalent road tax to be paid on brand-new cars
Price of the car Road tax to be paid < $50,000 5% $50,000 – $99,999 10% $100,000 – 149,999 15% >150,000 20%
- Price of the car and equivalent road tax to be paid on brand-new cars
- Hey! It’s that time of the year. Warm coffee, Gloomy weather, and filling taxes…..wait?WHAT!!
In this exercise, you will not only learn to condition but also to calculate taxes.Imagine user being a single filer for 2023. The tax rate by IRS can be found here. In total, there are 7 tax brackets, we will deal with 5 of them as shown in table below.<br>* Take an input salary from the user.* Based on the salary, calculate the tax amount the user owns to the IRS.
Use a series of if elif statements to achieve the resultSalary Tax < $11,000 10% $11,000 – $44,725 $1,100 + 12% of difference $44,725 – $95,375 $5,147 + 22% of the difference $95,375 – $182,100 $16,290 + 24% of the difference $182,100 – $231,250 $37,104 + 32% of the difference >$231,250 Contact our tax experts
6. Ask user for their age, gender(M or F), and marital status(Y or N). Based on the following table, print the appropriate message.
- If gender is female, “urban areas”
- If gender is male and age is between 20 and 40, “anywhere”
- If gender is male and age is between 40 and 60, “urban areas”
- Other input, “Error”
CHAPTER 3: LOOPS
1. Take a number from a user. Display number -1 to -n using a loop.
4. Write a Python program that prints all the numbers from 0 to 19(including them both) except 3 and 6.
For example, the number is 75869, so the output should be 5.
10. Write a program to display all prime numbers within a range
Note: A Prime Number is a number that cannot be made by multiplying other whole numbers. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers
Examples:
- 12 is not a prime number because it can be made by 3×4 = 12
- 37 is a prime number because no other whole numbers multiply together to make it.
11. Write a program to print the cube of all numbers from 1 to a given number.
If input is 6 print 1 8 27 64 125 216
12. Take a number from the user and reverse that integer number
Given: 587249
Expected output: 942785
13. Print the following pattern
CHAPTER 4: FUNCTION AND SCOPE RULES
1. Write a function to find power of a number but without using arithmetic operator
CHAPTER 5: LISTS
1. Perform the following functions(after each operation, print the list):
- Create an empty list
- Add 8 *random* numbers in that list(use random generator) and a loop and print it
- Remove the last element from the list. You must have 7 elements in this list, print the list and its length.
- Insert an element in fourth position in this list and now you have 8 elements. Print the list.
- Remove the first and seventh element from the list and now you have 6 elements. Print these final 6 elements.
CHAPTER 6: SETS AND TUPLES
1. Create a tuple of length 9 and write a Python program to get the 4th element from the last element of a tuple.
2. Write a Python program to check whether an element exists within a tuple. Add these elements to a new tuple named repeated_tuples.
3. Write a Python program to remove an item from a tuple.
Write a Python program to find the index of an item in a tuple.
Remove items from set1 that are not common to both set1 and set2
Update set1 by adding items from set2, except common items
CHAPTER 7: DICTIONARY