Test your knowledge on Variables, Data Types, Control Flow, and Imports.
1. If you define two variables, myVar and myvar, in Python, how does the interpreter treat them?
2. Which Python function is used to explicitly convert a value into a **string** data type?
3. If you execute x = int('45'), what is the final data type of the variable x?
4. What is the primary purpose of the if-else statement in Python?
5. In the vending machine scenario, what is the data type used to represent the current **stock** of a specific snack item?
6. What is the result of the following Python code snippet?
price = 2.5; money = 3; if money >= price: print('Purchase successful') else: print('Need more money')
7. Which of the following is a key characteristic of the **List** data type in Python?
8. What is the primary function of the **import** statement in Python?
9. If you have a variable age = 25, which of the following expressions uses a relational operator to check if age is **exactly 25**?
10. What is the data type of the value returned by the expression 3 > 5 in Python?
11. How should you correctly import only the pi constant and the sin function from the math library?
12. Which of the following is **NOT** a valid Python variable name?
13. What is the result of applying str() type casting to a list: str([1, 2, 3])?
14. What is the purpose of the **elif** keyword in a Python conditional block?
15. The **String** data type in Python is considered:
16. In a vending machine program, if you need to check if a snack costs less than $1.50 **OR** if the user has a special discount, which logical operator should be used?
17. What is the purpose of the dot (.) notation when calling a function after an import, such as math.sqrt(9)?
18. Given the list data = ['A', 'B', 'C', 'D'], what is the expression to access the letter 'C'?
19. What is the primary difference between the int and float data types?
20. If you have a list of expenses expenses = [10.5, 20, 5.0], which type casting function could you use to make the value of the first element an **integer**?
21. What will be the output of this conditional statement? x = 10; y = 5; if x > y and x < 20: print('A') else: print('B')
22. The **string** data type is a sequence of characters enclosed in:
23. What happens if you omit the required **indentation** for the code block inside an if statement?
24. Which of the following functions will convert a float like 5.8 into an integer, resulting in the value **5**?
25. What is the purpose of adding as alias_name to an import statement (e.g., import pandas as pd)?
26. Which of these lines correctly assigns the text 'Hello Python' to a variable named message?
27. What would be the typical conditional check in a vending machine to ensure a chosen item is **in stock**?
28. Which data type is used to represent the value **None** in Python, which often signifies the absence of a value or a null result?
29. The built-in function **list()** can convert a string like 'Python' into a list of what?
30. Which operator is the correct one to use for checking if two variables, a and b, have **different values**?