Docsity

WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) OBJECTIVE ASSESSMENT — 1,000+ QUESTIONS WITH, Exams of Nursing

Toggle sidebar
bg1
WGU E010 FOUNDATIONS OF PROGRAMMING
(PYTHON) OBJECTIVE ASSESSMENT — 1,000+
QUESTIONS WITH VERIFIED ANSWERS &
DETAILED RATIONALES (UPDATED EDITION)
Course: E010 — Foundations of Programming (Python)
Institution: Western Governors University (WGU)
Assessment: Objective Assessment (OA) — Versions V1 & V2
Total Questions: 1,000+
Format: Multiple Choice, Code Output, Code Completion, Scenario-Based
Numbering: Continuous from Question 1 through Question 1,000+
CHAPTER 1: PYTHON SYNTAX, VARIABLES & DATA
TYPES (QUESTIONS 1–150)
1. What is the correct way to output the string "Hello, World!" in
Python?
A. printf("Hello, World!")
B. console.log("Hello, World!")
C. print("Hello, World!")
D. echo "Hello, World!"
Answer: C
Rationale: Python's built-in print() function outputs text to the console. The
other options are used in other languages (C, JavaScript, PHP).
Understanding the correct syntax for output is foundational to Python
programming.
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 WGU E010 FOUNDATIONS OF PROGRAMMING (PYTHON) OBJECTIVE ASSESSMENT — 1,000+ QUESTIONS WITH and more Exams Nursing in PDF only on Docsity!

WGU E010 FOUNDATIONS OF PROGRAMMING

(PYTHON) OBJECTIVE ASSESSMENT — 1,000+

QUESTIONS WITH VERIFIED ANSWERS &

DETAILED RATIONALES (UPDATED EDITION)

Course: E010 — Foundations of Programming (Python) Institution: Western Governors University (WGU) Assessment: Objective Assessment (OA) — Versions V1 & V Total Questions: 1,000+ Format: Multiple Choice, Code Output, Code Completion, Scenario-Based Numbering: Continuous from Question 1 through Question 1,000+

CHAPTER 1: PYTHON SYNTAX, VARIABLES & DATA

TYPES (QUESTIONS 1–150)

1. What is the correct way to output the string "Hello, World!" in Python? A. printf("Hello, World!") B. console.log("Hello, World!") C. print("Hello, World!") D. echo "Hello, World!" Answer: C Rationale: Python's built-in print() function outputs text to the console. The other options are used in other languages (C, JavaScript, PHP). Understanding the correct syntax for output is foundational to Python programming.

2. Which of the following is a valid variable name in Python? A. 2nd_place B. my-var C. my_var D. class Answer: C Rationale: Python variable names must start with a letter or underscore, cannot contain hyphens, and cannot be Python keywords like class. Underscores are allowed and commonly used. 3. What is the data type of the value 3.14 in Python? A. int B. float C. string D. boolean Answer: B Rationale: Numbers with a decimal point are of the float (floating-point) type. Integers have no decimal point. 4. What is the output of print(type(10))? A. B. int C. 'int' D. Answer: A Rationale: The type() function returns the type of an object, and printing it displays . 5. What is the output of print(type(10 / 2))? A.

8. Which of the following is NOT a valid way to create a string in Python? A. "hello" B. 'hello' C. hello D. """hello""" Answer: C Rationale: Backticks are not used to create strings in Python. Strings can be created with single quotes, double quotes, or triple quotes. 9. Given my_list = [1, 2, 3, 4] , what does my_list[2] return? A. 1 B. 2 C. 3 D. 4 Answer: C Rationale: Python list indexing starts at 0. Index 2 gives the third element, which is 3. 10. What will this code print? python x = "Hello" print(x[ 1 ]) A. H B. e C. l D. o

Answer: B Rationale: String indexing starts at 0. Index 1 gives the second character, which is "e".

11. What is the correct file extension for a Python source file? A. .py B. .python C. .pyt D. .pt Answer: A Rationale: Python source files use the .py extension. Other extensions are not standard for Python source code. 12. Which of the following is a valid variable name in Python? A. 2nd_variable B. my-variable C. _my_variable D. my variable Answer: C Rationale: Variable names can start with a letter or underscore, followed by letters, digits, or underscores. They cannot start with a digit, contain hyphens, or spaces. 13. What data type is the result of the expression 5 / 2 in Python 3? A. int B. float C. str D. bool

Answer: A Rationale: The input() function reads a line from standard input and returns it as a string.

17. What is the result of len("Hello")? A. 4 B. 5 C. 6 D. o Answer: B Rationale: The len() function returns the number of characters in the string "Hello", which is 5. 18. Which of the following is a mutable data type in Python? A. tuple B. string C. list D. frozenset Answer: C Rationale: Lists are mutable, meaning their elements can be changed after creation. Tuples, strings, and frozensets are immutable. 19. What is the correct syntax to create a single-line comment in Python? A. // This is a comment B. # This is a comment C. /* This is a comment */ D. -- This is a comment

Answer: B Rationale: Python uses the hash symbol # for single-line comments. Other options show comment syntax from other languages.

20. What will be the output of the following code? python x = 5 y = 2 print(x ** y) A. 7 B. 10 C. 25 D. 32 Answer: C Rationale: The ** operator is exponentiation. 5 ** 2 = 25. 21. Which statement correctly uses the modulo operator in Python? A. result = 10 % 3 B. result = 10 & 3 C. result = 10 @ 3 D. result = 10 # 3 Answer: A Rationale: The modulo operator % returns the remainder of a division operation. 10 % 3 = 1. 22. What is the correct way to declare a variable in Python that stores the number 42? A. var x = 42 B. x == 42

C. 0

D. 3.

Answer: B Rationale: The modulo operator % returns the remainder. 10 % 3 = 1.

26. What is the result of int("25") + 5? A. "255" B. 30 C. 25 D. Error Answer: B Rationale: int("25") converts the string to the integer 25. 25 + 5 = 30. 27. What is the result of str(25) + "5"? A. 30 B. "255" C. 255 D. Error Answer: B Rationale: str(25) converts the integer to the string "25". String concatenation with + produces "255". 28. What is the output of print(float("3.14"))? A. 3 B. 3. C. "3.14" D. Error Answer: B Rationale: float("3.14") converts the string "3.14" to the float 3.14.

29. Which of the following is a valid Python identifier? A. 2nd_value B. my-value C. class D. _total_count Answer: D Rationale: Identifiers may start with a letter or underscore and may contain letters, digits, and underscores. They cannot start with a digit or be a reserved keyword such as class. 30. The value 3.14 is stored in a variable. Its data type is: A. float B. int C. complex D. str Answer: A Rationale: A numeric literal containing a decimal point is a floating-point number (float). 31. A developer writes print("Hello") and runs the script. The console displays: A. "Hello" including the quotation marks B. Hello without quotation marks C. print("Hello") D. A syntax error Answer: B Rationale: The print function outputs the evaluated string value; the quotes are delimiters in the source code and do not appear in the output.

35. What is the output of print(5 > 3 and 2 < 1)? A. True B. False C. None D. Error Answer: B Rationale: 5 > 3 is True, but 2 < 1 is False. The and operator returns True only when both conditions are True, so the result is False. 36. What is the output of print(5 > 3 or 2 < 1)? A. True B. False C. None D. Error Answer: A Rationale: 5 > 3 is True. The or operator returns True if at least one condition is True. 37. What is the output of print(not (5 > 3))? A. True B. False C. None D. Error Answer: B Rationale: 5 > 3 is True. The not operator negates the value, so not True is False. 38. What is the output of print(2 == 2.0)? A. True B. False

C. Error D. None Answer: A Rationale: In Python, 2 and 2.0 are considered equal in value. The == operator compares values, not types.

39. What is the output of print(2 is 2.0)? A. True B. False C. Error D. None Answer: B Rationale: The is operator checks identity (whether both operands refer to the same object). 2 is an integer object and 2.0 is a float object, so they are not the same object. 40. What is the correct way to convert a string to an integer in Python? A. str(25) B. int("25") C. float("25") D. bool("25") Answer: B Rationale: The int() function converts a string or number to an integer. 41. What is the output of print("Hello" + " " + "World")? A. HelloWorld B. Hello World C. "Hello World" D. Error

B. n C. o D. Error Answer: B Rationale: Negative indexing starts from the end. -1 gives the last character, which is "n".

46. What is the output of print("Python"[1:4])? A. Pyt B. yth C. ytho D. Pyth Answer: B Rationale: Slicing [1:4] returns characters from index 1 up to (but not including) index 4: indices 1, 2, 3 → "yth". 47. What is the output of print("Python"[2:])? A. Py B. thon C. th D. Pyth Answer: B Rationale: Slicing [2:] returns characters from index 2 to the end: "thon". 48. What is the output of print("Python"[:3])? A. Pyt B. thon C. Pyth D. yth

Answer: A Rationale: Slicing [:3] returns characters from the beginning up to (but not including) index 3: "Pyt".

49. What is the output of print("Python"[::-1])? A. Python B. nohtyP C. n D. Error Answer: B Rationale: The slice [::-1] reverses the string, producing "nohtyP". 50. Which of the following is the correct way to assign the value 10 to a variable named x? A. x == 10 B. x = 10 C. 10 = x D. int x = 10 Answer: B Rationale: Assignment uses the single equals sign =. x == 10 is a comparison, 10 = x is invalid, and int x = 10 is C/C++ syntax. 51. What is the output of print(type(True))? A. B. C. D. Answer: B Rationale: True and False are the only values of type bool.

C. 3.

D. Error Answer: B Rationale: The round() function rounds to the nearest integer. round(3.9) returns 4.

56. What is the result of round(3.14159, 2)? A. 3. B. 3. C. 3. D. 3 Answer: A Rationale: The second argument specifies the number of decimal places. round(3.14159, 2) returns 3.14. 57. What is the output of print(abs(-5))? A. - B. 5 C. 0 D. Error Answer: B Rationale: The abs() function returns the absolute value. abs(-5) returns 5. 58. What is the output of print(pow(2, 3))? A. 6 B. 8 C. 9 D. 5

Answer: B Rationale: The pow(2, 3) function computes 2 raised to the power of 3, which is 8.

59. What is the output of print(max(1, 5, 3))? A. 1 B. 5 C. 3 D. 9 Answer: B Rationale: The max() function returns the largest argument, which is 5. 60. What is the output of print(min(1, 5, 3))? A. 1 B. 5 C. 3 D. 9 Answer: A Rationale: The min() function returns the smallest argument, which is 1. 61. What is the output of print(sum([1, 2, 3, 4]))? A. 1234 B. 10 C. 4 D. Error Answer: B Rationale: The sum() function adds all elements in the iterable. 1 + 2 + 3 + 4 = 10.