Loading samples...
Loading samples...
py-sample-16
Mixed topics: Data types, operators, control flow
What is 5 // 2 in Python?
Which is immutable?
What does 'abc' * 2 produce?
What is result of True + True?
Which operator checks membership?
What does range(3, 8, 2) produce?
What is len('hello world')?
Which creates an empty set?
What is output of 2 ** 3 ** 2?
What does list('abc') return?
Explain the difference between == and is operators.
[3 marks]What is list slicing? Explain with [start:stop:step].
[3 marks]Explain the difference between break and continue.
[3 marks]What are truthy and falsy values? Give examples.
[3 marks]Explain type casting in Python with examples.
[3 marks]What is the difference between / and // operators?
[3 marks]Explain dictionary.get() vs dictionary[key] access.
[3 marks]What is string formatting? Explain f-strings.
[3 marks]Explain how to swap two variables in Python.
[3 marks]What is the use of enumerate() function?
[3 marks]Write a program to find all prime numbers between 1 and 100.
[5 marks]Create a program to count the frequency of each character in a string.
[5 marks]Write a program to find the second largest element in a list.
[5 marks]Create a program to check if a string is a palindrome.
[5 marks]Write a program to generate Pascal's triangle up to n rows.
[5 marks]Create a simple contact book with add, search, and delete operations.
[5 marks]Predict output: x = [1, 2, 3, 4, 5] print(x[1:4:2])
[2 marks]Explanation:Start at index 1, stop before 4, step 2. Gets elements at 1 and 3.
Find error: if x > 5: print('Greater')
[2 marks]Explanation:x is not defined before use. Initialize x = some_value first.
Predict output: a = 5 b = 5.0 print(a == b, a is b)
[2 marks]Explanation:== checks value (5 == 5.0), is checks identity (different types, different memory).
Find error: for i in range(5): print(i) i += 1
[2 marks]Explanation:Loop variable i exists after loop in Python. No error, but modifying it may be confusing.
Predict output: s = 'hello' s = s.upper() print(s)
[2 marks]Explanation:upper() returns new string, doesn't modify original. Reassignment makes s point to new string.
Find error: def func(): x = 10 func() print(x)
[2 marks]Explanation:x is local to func(). Not accessible outside. Use return x or make x global.
Predict output: my_dict = {'a': 1, 'b': 2} print('c' in my_dict) print(my_dict.get('c', 0))
[2 marks]Explanation:in checks keys, 'c' not present so False. get() with default returns 0 for missing key.
Find error: L = [1, 2, 3] print(L[3])
[2 marks]Explanation:Valid indices are 0, 1, 2. Index 3 doesn't exist.