
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































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+
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. B. C. D.
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: B Rationale: The division operator / always returns a float in Python 3, even if the operands are integers. 14. Which operator is used for exponentiation in Python? A. ^ B. ** C. // D. % Answer: B Rationale: The ** operator raises a number to a power. The ^ operator is bitwise XOR, // is floor division, and % is modulus.
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. x = 42 D. declare x = 42 Answer: C Rationale: In Python, variables are assigned values using the single equals sign =. Other options show syntax from other languages or use incorrect Python syntax. 23. Which of the following is a valid Python data type? A. string B. number C. boolean D. float Answer: D Rationale: Python has several built-in data types including int, float, str, bool, and complex. While "string," "boolean," and "number" are conceptual terms, they are not the actual Python data type names. 24. What is the output of print(10 // 3)? A. 3. B. 3
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. 32. Python is described as a dynamically typed language. This means that: A. Every variable must be declared with an explicit type annotation before use B. All variables are permanently locked to the first type they receive C. The type of a name is determined by the object it currently references and can change D. Type checking occurs only at compile time Answer: C Rationale: Names are bindings to objects. The type belongs to the object, not the name, so the same name may later refer to a different type of object. 33. What is the output of print(type(10 / 2))? A. B. C. D. Answer: B Rationale: In Python, the / operator performs true division and always returns a float, even when the numbers divide evenly. 34. Which of the following data types is immutable in Python? A. list
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 Answer: B Rationale: String concatenation with + joins the strings. The space is included as a string literal. 42. What is the output of print("Ha" * 3)? A. HaHaHa B. Ha C. Error D. Ha Ha Ha Answer: A Rationale: The * operator repeats a string. "Ha" * 3 produces "HaHaHa". 43. What is the output of print(len("Python"))? A. 5 B. 6 C. 7 D. P Answer: B Rationale: The string "Python" has 6 characters: P, y, t, h, o, n. 44. What is the output of print("Python"[0])? A. P B. y C. n D. Error
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.
52. What is the output of print(True + 1)? A. True B. 2 C. Error D. True Answer: B Rationale: In Python, True is a subclass of int and has the value 1. True + 1 = 2. 53. What is the output of print(False + 1)? A. False B. 1 C. Error D. False Answer: B Rationale: False has the value 0. False + 1 = 1. 54. What is the result of int(3.9)? A. 3 B. 4 C. 3. D. Error Answer: A Rationale: The int() function truncates (does not round) the decimal portion, returning
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. 62. What is the output of print(list("abc"))? A. ['a', 'b', 'c'] B. "abc"
C. ['abc'] D. Error Answer: A Rationale: The list() function converts an iterable (like a string) into a list of its characters.
63. What is the output of print(tuple([1, 2, 3]))? A. [1, 2, 3] B. (1, 2, 3) C. {1, 2, 3} D. Error Answer: B Rationale: The tuple() function converts an iterable into a tuple. 64. What is the output of print(set([1, 2, 2, 3]))? A. {1, 2, 3} B. [1, 2, 3] C. (1, 2, 3) D. {1, 2, 2, 3} Answer: A Rationale: A set automatically removes duplicates. set([1, 2, 2, 3]) produces {1, 2, 3}. 65. What is the output of print(dict([(1, 'a'), (2, 'b')]))? A. {1: 'a', 2: 'b'} B. [1: 'a', 2: 'b'] C. (1: 'a', 2: 'b') D. Error