Lesson 17 of 18 · 2 min · practice
Practice Questions
Q1. You are building a student profile app. Create variables for: full name (string), roll number (integer), CGPA (float), branch (string), year (integer), and is_hosteler (boolean). Print each variable along with its type using type().
Q2. What will each line print? Explain WHY each result is what it is:
print(17 // 5) print(17 % 5) print(2 ** 10) print(10 / 2) print(type(10 / 2)) print(type(10 // 2))
Q3. 500 students need to be divided into lab groups of 28. Using // and %, find: (a) how many complete groups of 28 can be formed, and (b) how many students are left without a complete group.
Q4. Given course = "Data Science and Artificial Intelligence", write code to:
- Print it in all uppercase
- Extract "Data Science" using slicing
- Extract "Artificial Intelligence" using slicing
- Count how many times the letter 'a' appears (case-insensitive)
- Check if the course starts with "Data" and ends with "Intelligence"
Q5. Write a program that asks the user for their name, age, and CGPA. Print a formatted summary showing: name, age, year they will graduate (current year + 4 - (age - 18)), and whether their CGPA qualifies for "Distinction" (≥3.5), "Merit" (≥3.0), or "Pass" (below 3.0). Use f-strings for all output.
Q6. Explain with examples: what is the difference between = and == in Python? Why is this the most common mistake beginners make?
Q7. Find and fix ALL errors in this code:
1student_name = input(Enter your name: )
score = 85
message = "Your score is " + score
print(message)
If score >= 60:
print("You passed")Q8. Write a Python program that works like a simple calculator. Ask the user for two numbers and an operation (+, -, *, /). Perform the chosen operation and display the result. For division, check that the second number is not zero before dividing.
Q9. Demonstrate the difference between these four things with actual print() output:
42— integer42.0— float"42"— stringint("42")— type conversion
Q10. Given the string s = "Open Institute of Science and Technology", use ONE line of code for each: (a) reverse the string, (b) count the spaces, (c) replace "Institute" with "University", (d) extract every third character, (e) check if the string contains "Science".
