Docsity

Python Coding Exam Questions and Answers, Exams of Advanced Education

Toggle sidebar
bg1
Python Coding Study Guide Final
Exam Questions and Answers
Which of the following Python 3 instructions will produce the output Hello
World?
Print("Hello World")
print "Hello World"
print "Hello World"
print("Hello World") - ANSWERS-print("Hello World")
What character(s) is used at the start of a line in Python to indicate that what
follows should be treated as a comment? - ANSWERS-#
Which of the following is a type in Python?
int
bool
list
All of the above - ANSWERS-All of the above
A fragment of code that causes a data type to be evaluated? - ANSWERS-
Expression
A single unit of code that the Python interpreter can execute? - ANSWERS-
Statement
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Python Coding Exam Questions and Answers and more Exams Advanced Education in PDF only on Docsity!

Python Coding Study Guide Final

Exam Questions and Answers

Which of the following Python 3 instructions will produce the output Hello World? Print("Hello World") print "Hello World" print "Hello World" print("Hello World") - ANSWERS-print("Hello World") What character(s) is used at the start of a line in Python to indicate that what follows should be treated as a comment? - ANSWERS-# Which of the following is a type in Python? int bool list All of the above - ANSWERS-All of the above A fragment of code that causes a data type to be evaluated? - ANSWERS- Expression A single unit of code that the Python interpreter can execute? - ANSWERS- Statement

What is the output of the following code in Python 3? print(1 and 0) - ANSWERS- If we have just 1 + 1 what are the outcome in command prompt (Shell Mode) and script? - ANSWERS-2 and blank This control structure in Python keeps executing a code block while the test is True? - ANSWERS-While loop Python keyword used to create a user function? - ANSWERS-def This control structure in Python executes a code block for a specified number of times? - ANSWERS-For loop What will be the result of the following Python 3 statement? temperature = "3" + "5" - ANSWERS-' 35 ' What will be the output of the following code in Python 3? number = 6 number = number + 4 lucky_number = 10 * number print(lucky_number/number) - ANSWERS- What is the output of the following code in Python 3? print("Ozymandius"[2:4]) - ANSWERS-ym

return 1 else: return n * factorial(n-1) print(factorial(3)) - ANSWERS- Standard language for managing and querying relational databases? - ANSWERS-SQL Behaves much like a list, but permits non-integer types to be used as the indices. Can be thought of as a set of non-sequential key-value pairs. - ANSWERS-Dictionary Items in a dictionary are... - ANSWERS-unordered so they cannot be referenced using their ordinal position...the actual order of the items is unpredictable. What results from "3" + "5"? Why? - ANSWERS-' 35'. Because they are surrounded by quotation marks, the interpreter treats the values as letters and concatenates them. What is 6 + 10 / 2? What is it called when calculation is correct but not meant for this result? - ANSWERS-11. Semantically Incorrect. Consider the following: lucky_number = 42 print(lucky_number) 42

What is lucky_number in this case? - ANSWERS-A variable: gives a name to a value. Consider the following: lucky_number = lucky_number * 2 print(lucky_number) 84 What happened? - ANSWERS-Assigned value of lucky_number * 2 to variable lucky_number. This changes the value of the variable lucky_number. Variable names are case sensitive. Single unit of code that the Python interpreter can execute - ANSWERS- Statement Any fragment of code that causes a data type to be evaluated - ANSWERS- Expression What are the different types in Python? - ANSWERS-Integer, Floating Point Number, String, Boolean, List Data type for text and contained within quotation marks - ANSWERS-String; can consist of: Letters (both uppercase and lowercase); numbers; special characters; spaces; or combo of above What is the difference/similarities between string and list - ANSWERS-String data types consist of a sequence of characters. They are similar to the list data type. The main difference between the two is that a list can contain any data type, while string can only contain characters.

What is the basic syntax of a Method? - ANSWERS-Dot notation:

.(, , ...) Object is typically a variable name What is the difference between .append and. extend? - ANSWERS-.append adds the string value "arthropod" to the end of the list, while .extend treats the string "bird" as a sequence of values and adds each character of the string as a separate value. Python interpreter always treats the values the user inputs at the keyboard as? - ANSWERS-A string. What is the purpose of indentation? - ANSWERS-To define blocks of code and at the same time enforce good coding practice. Each change in indentation is used to determine when a code block starts or stops. Define if statement and its structure: - ANSWERS-Executes a statement block based on results of a test expressed by a conditional statement Structure: if : elif : else:

What is if-else? - ANSWERS-if statement can be used together with else What is if-elif? - ANSWERS-- if statement can be used together with one or more elif statements to set multiple tests.

  • The code block related to the test that is satisfied will be executed.
  • If none of the conditions is met, then either the else code block will be executed, or if there is no else code block, none of the conditional code blocks will be executed. Define while loop and its structure: - ANSWERS-Keeps executing a code block while the test is True while : Define for loop and its structure: - ANSWERS-Execute a code block for a specified number of times. Structure: for in : The is used as a counter that controls how many times the code block is executed. The is a sequence of values such as a list or a string. The takes each

def lucky_number(): import random x = random.randrange(10) print("Your lucky number is: ",x) lucky_number() - ANSWERS-When a function calls other functions. Here is an example of a script. What does this script do? def factorial(n): if n == 1: return 1 else: return n * factorial(nโ€1) print(factorial(5)) - ANSWERS-This is an example of recursion.