Docsity

Beingcert Certified Python Developer Exam, Exams of Technology

Toggle sidebar
bg1
Beingcert Certified Python Developer
Exam
**Question 1. Which statement correctly describes the difference between an interpreted
language and a compiled language?**
A) Interpreted languages are always faster than compiled languages.
B) Compiled languages execute source code directly without translation.
C) Interpreted languages translate source code into machine code at runtime.
D) Compiled languages cannot be executed on multiple platforms.
**Answer: C**
**Explanation:** An interpreted language translates source code line‑by‑line during execution,
whereas a compiled language translates the whole program to machine code beforehand.
**Question 2. What is the output of the following code?
```python
x = 5
y = 2
print(x // y)
```**
A) 2.5
B) 2
C) 3
D) 0
**Answer: B**
**Explanation:** The `//` operator performs floor division, discarding the fractional part; 5 // 2
equals 2.
**Question 3. Which of the following is a valid variable name in Python?**
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Beingcert Certified Python Developer Exam and more Exams Technology in PDF only on Docsity!

Exam

Question 1. Which statement correctly describes the difference between an interpreted language and a compiled language? A) Interpreted languages are always faster than compiled languages. B) Compiled languages execute source code directly without translation. C) Interpreted languages translate source code into machine code at runtime. D) Compiled languages cannot be executed on multiple platforms. Answer: C Explanation: An interpreted language translates source code line‑by‑line during execution, whereas a compiled language translates the whole program to machine code beforehand. **Question 2. What is the output of the following code?

x = 5 y = 2 print(x // y) ```** A) 2. B) 2 C) 3 D) 0 **Answer: B** **Explanation:** The `//` operator performs floor division, discarding the fractional part; 5 // 2 equals 2. **Question 3. Which of the following is a valid variable name in Python?** ## Exam A) 2nd_place B) total‑sum C) _averageScore D) class **Answer: C** **Explanation:** Variable names may start with a letter or underscore; `_averageScore` follows the rules. `2nd_place` starts with a digit, `total‑sum` contains a hyphen, and `class` is a reserved keyword. **Question 4. What does the `input()` function return?** A) An integer B) A float C) A string D) A boolean **Answer: C** **Explanation:** `input()` always returns the entered data as a string; conversion is required for other types. **Question 5. Which operator tests whether two variables refer to the same object?** A) `==` B) `is` C) `!=` D) `in` **Answer: B** **Explanation:** The `is` operator checks identity (whether both operands point to the same object), whereas `==` checks value equality. ## Exam ## A) `4, 2, 3` ## B) `(4, 2, 3)` C) `TypeError` D) No output, the code runs silently. **Answer: C** **Explanation:** Tuples are immutable; attempting to assign to an element raises a `TypeError`. **Question 9. How can you unpack a tuple `coords = (5, 10)` into variables `x` and `y`?** A) `x, y = coords` B) `x = coords[0]; y = coords[1]` C) Both A and B are correct D) `coords.unpack()` **Answer: C** **Explanation:** Both direct unpacking (`x, y = coords`) and indexing achieve the same result; there is no `unpack()` method. **Question 10. Which of the following statements creates a dictionary with keys `'a'` and `'b'` and corresponding values `1` and `2`?** A) `{'a': 1, 'b': 2}` B) `{'a' = 1, 'b' = 2}` C) `dict('a':1, 'b':2)` D) `{'a', 1, 'b', 2}` **Answer: A** **Explanation:** Dictionary literals use colon `:` to separate keys and values. Option B uses assignment syntax, C is invalid syntax for `dict()`, and D creates a set. ## Exam **Question 11. How do you access the value associated with key `'name'` in dictionary `person = {'name': 'Alice', 'age': 30}`?** A) `person.name` B) `person['name']` C) `person.get(name)` D) `person->name` **Answer: B** **Explanation:** Dictionary values are retrieved using square‑bracket notation with the key as a string. `person.get('name')` would also work, but option C omitted quotes. **Question 12. Which operation returns a set containing elements present in both `set1` and `set2`?** A) `set1.union(set2)` B) `set1.intersection(set2)` C) `set1.difference(set2)` D) `set1.symmetric_difference(set2)` **Answer: B** **Explanation:** `intersection` yields common elements. `union` combines all, `difference` subtracts, and `symmetric_difference` returns elements in one set but not both. **Question 13. What will be printed after executing the following code? ```python s = {1, 2, 3} s.add(2) print(len(s)) ## Exam self.make = make self.model = model 

C)

class Car: def __init__(self): make = make model = model 

D)

class Car: def __init__(self, make, model): make = self.make model = self.model 

Answer: A Explanation: The initializer must accept self as the first parameter and assign the passed values to self.make and self.model.

Exam

Question 15. In object‑oriented programming, which principle is demonstrated by making an attribute start with double underscores (__) in a class? A) Inheritance B) Polymorphism C) Encapsulation D) Abstraction Answer: C Explanation: Name mangling with double underscores makes the attribute harder to access from outside the class, supporting encapsulation. Question 16. Given the following classes, which statement correctly creates a Dog object that inherits from Animal?

class Animal: def speak(self): print("Generic sound") class Dog(Animal): def speak(self): print("Woof") 

A) d = Dog() B) d = Animal(Dog) C) d = Dog.speak()

Exam

C) Class attributes can only be integers. D) Changing a class attribute changes the value for the class only, not for any instances. Answer: A Explanation: Class attributes belong to the class namespace and are common to all instances, while instance attributes live in each object's __dict__. **Question 20. What is the output of the following code?

class Counter: count = 0 def __init__(self): Counter.count += 1 c1 = Counter() c2 = Counter() print(Counter.count) ```** A) 0 B) 1 C) 2 D) 3 **Answer: C** **Explanation:** Each instantiation increments the class attribute `count`. After two objects, the value is 2. ## Exam **Question 21. Which of the following correctly implements a conditional statement that prints “Adult” when `age` is 18 or older, and “Minor” otherwise?** A) ```python if age >= 18: print("Adult") else: print("Minor") 

B)

if age > 18: print("Adult") elif: print("Minor") 

C)

if age >= 18: ## Exam ## B) 5 ## C) 6 ## D) 7 **Answer: C** **Explanation:** Iterations: i=0→2→4→6; when i becomes 6 the condition `i < 5` is false, loop exits with i=6. **Question 23. Which statement correctly exits a `for` loop prematurely?** A) `continue` B) `break` C) `pass` D) `exit()` **Answer: B** **Explanation:** `break` terminates the nearest enclosing loop immediately. `continue` skips to the next iteration, `pass` does nothing, and `exit()` terminates the program. **Question 24. What does the `pass` statement do inside a loop or function?** A) Stops execution of the loop. B) Skips the current iteration. C) Executes a no‑operation placeholder. D) Raises a `PassError`. **Answer: C** **Explanation:** `pass` is a null statement; it does nothing and is often used as a placeholder. **Question 25. Which of the following definitions creates a function that returns the square of its argument?** ## Exam ## A) ```python def square(x): return x * x 

B)

def square(x): print(x * x) 

C)

def square(x): x * x 

D)

def square(x): ## Exam **Question 28. What will be printed by this code? ```python def add(a, b=5): return a + b print(add(3)) ```** A) 3 B) 5 C) 8 D) Error **Answer: C** **Explanation:** The function uses a default value of `b=5`. Calling `add(3)` supplies only `a`, so `b` defaults to 5; result is 8. **Question 29. Which lambda expression correctly doubles its input `x`?** A) `lambda x: x * 2` B) `lambda x: return x * 2` C) `lambda: x * 2` D) `lambda x, y: x * 2` **Answer: A** **Explanation:** A lambda consists of `lambda parameters: expression`. Option A follows this pattern; option B uses illegal `return`, C lacks a parameter, D has an extra unused parameter. ## Exam **Question 30. What is the purpose of the `yield` keyword in a function?** A) To return multiple values at once. B) To pause execution and produce a generator. C) To raise an exception. D) To terminate the program. **Answer: B** **Explanation:** `yield` turns a function into a generator, allowing it to produce a series of values lazily while maintaining state between calls. **Question 31. Which of the following statements creates a generator that yields numbers from 0 to 4?** A) ```python def gen(): for i in range(5): yield i 

B)

def gen(): return range(5) 

Exam

D) math.import(sqrt) Answer: B Explanation: The from <module> import <name> syntax imports a specific attribute. Question 34. What does the os.path.join('folder', 'file.txt') function return on a Unix‑like system? A) 'folder/file.txt' B) 'folder\\file.txt' C) 'folder/filetxt' D) 'folderfile.txt' Answer: A Explanation: os.path.join concatenates path components using the appropriate separator (/ on Unix). Question 35. Which mode should be used to open a file for appending text without truncating existing content? A) 'r' B) 'w' C) 'a' D) 'x' Answer: C Explanation: 'a' opens a file for appending; data is written at the end and the file is created if it does not exist. Question 36. Given a CSV file data.csv, which standard library module provides the reader object to iterate rows?

Exam

A) json B) csv C) pandas D) xml Answer: B Explanation: The csv module contains reader and writer classes for CSV handling. Question 37. What exception is raised when attempting to open a file that does not exist using mode 'r'? A) FileNotFoundError B) IOError C) OSError D) ValueError Answer: A Explanation: In Python 3, trying to read a non‑existent file raises FileNotFoundError, a subclass of OSError. Question 38. Which of the following statements correctly catches any exception without specifying its type? A)

except Exception: handle()