Loading samples...
Loading samples...
py-sample-5
Complete Assessment of Python Fundamentals
Which is a valid variable name?
What is the output of print(type(5/2))?
Which is NOT a Python keyword?
What does 'pass' statement do?
How to check if object is of specific type?
What is the scope of a variable defined inside a function?
Which function rounds a number to nearest integer?
What is the result of '5' + str(5)?
How to get ASCII value of a character?
What does help() function do?
Explain the difference between keywords and identifiers with examples.
[3 marks]What are Python's naming conventions for variables? List the rules.
[3 marks]Explain the concept of dynamic typing in Python. How is it different from static typing?
[3 marks]What is the difference between global and local variables?
[3 marks]Explain the use of del statement with examples.
[3 marks]What are docstrings? How are they different from comments?
[3 marks]Explain the assert statement with a practical example.
[3 marks]What is the difference between eval() and exec() functions?
[3 marks]Explain the concept of garbage collection in Python.
[3 marks]What is the purpose of __name__ == '__main__'? Explain.
[3 marks]Write a program that calculates compound interest using the formula A = P(1 + r/n)^(nt).
[5 marks]Create a program to convert binary to decimal and vice versa.
[5 marks]Write a program to solve a quadratic equation ax² + bx + c = 0.
[5 marks]Create a program that generates a simple password from user's initials and birth year.
[5 marks]Write a program to format a number with comma separators and fixed decimal places.
[5 marks]Create a program that calculates age in years, months, and days from birthdate.
[5 marks]Find error: def calculate(): result = 10 print(result)
[3 marks]Explanation:result is a local variable inside calculate(). It's not accessible outside the function.
Predict output: x = 10 def func(): x = 20 print(x) func() print(x)
[3 marks]Explanation:Local x shadows global x. Inside func(), local x=20 is used. Outside, global x=10 is used.
Find error: def greet(name='World', greeting): print(greeting, name)
[3 marks]Explanation:Default arguments must come after non-default arguments. Reverse the order.
Predict output: print(0.1 + 0.2 == 0.3) print(round(0.1 + 0.2, 1) == 0.3)
[2 marks]Explanation:Floating point precision issue. 0.1+0.2 is actually 0.30000000000000004. Round fixes this.
Find error: numbers = [1, 2, 3] print(numbers[3])
[2 marks]Explanation:Valid indices are 0, 1, 2 for a 3-element list. Index 3 doesn't exist.
Predict output: a = [1, 2, 3] b = a c = a[:] a.append(4) print(b) print(c)
[3 marks]Explanation:b is reference to same list as a. c is a shallow copy using slicing, so it's independent.
Find error: import math print(math.pi())
[2 marks]Explanation:math.pi is a constant (float), not a function. Remove the parentheses.
Predict output: my_dict = {'a': 1, 'b': 2} print(my_dict.get('c', 'Not found')) print(my_dict['c'])
[2 marks]Explanation:get() returns default if key missing. Direct access with [] raises KeyError if key missing.