Linkedin: Programming Foundations Fundamentals: Q&A

1. Programming Basics

Q: If you were writing your source code in the JavaScript programming language, what file extension would you use to save your file?
A: .js

Q: What is the standard extension to use for a Python source code file?
A: .py

Q: If you were developing an application for an iPhone, which IDE would you use? - Android Studio / RubyMine / XCode
A: XCode

Q: Which IDE feature allows you to get code suggestions while you are typing?
A: IntelliSense

Q: Which tool is used to write source code?
A: A text editor.

Q: Which language does not use a hybrid compiler/interpreter approach? - C++ / C# / Python / Java
A: C++

Q: Why doesn't a Python file execute when you double-click it?
A: Double-clicking does not run the Python Interpreter on the source code.

Q: Which language is considered an interpreted language? - C / JavaScript / C++ / Objective-C
A: JavaScript

Q: How would you write the "Hello, world!" program in Python?
A: print("Hello, world!")

Q: Source code is written in rich text.
A: FALSE

Q: Programming can be defined as: converting ideas into _____ that a computer can understand.
A: instructions

Q: Why do computer instructions need to be sequential?
A: The order in which these instructions are executed is important.

Q: In programming, a crash is when your program stops early or freezes because something unexpected happened.
A: TRUE

Q: Why are there many programming languages?
A: To address many different computing needs.

2. Programming Syntax

Q: You have Python 3 installed. How will you run the Python code in the file "process.py" on the command-line prompt?
A: python3 process.py

Q: To get Python code suggestions, you need to tell VS Code which Python interpreter to use.
A: TRUE

Q: Which statement is true regarding Python support in VS Code?
A: You need to install a VS Code extension to support Python.

Q: What does this expression evaluate to?
2 * 3 + 2 * 5
A: 16

Q: Which expression evaluates to 20?
A: (2 + 3) * 4

Q: Which is an example of a syntax error?
A: 2 (4*2)

Q: Which of these is NOT a reason why we chose Python as the language for the course?
A: Highly performant.

Q: Which concern could be considered a disadvantage of Python under certain circumstances?
A: Python is a general-purpose language.

Q: Why does VS Code need a Python interpreter to be specified?
A: To provide code suggestions.

Q: When working with the Terminal inside of VSCode, how can you expand the pane?
A: Click the up arrow.

Q: In the Python Terminal, what is printed when running the following line?
5 * 2 + 1
A: 11

Q: What does this expression evaluate to?
3 + 2 * 5
A: 13

Q: The code below, which is supposed to print the value of the variable x, is not working. Which category does the error fall under?
x = 5
 print("x")
A: Semantic.

Q: Which statement is true regarding Python on a Mac?
A: A Mac comes with a version of Python already installed.

Q: Which is an example of a runtime error?
A: 
name = "It's me!"
 print("Hello.", Name)
 
Q: Typing “What is 2 plus 2?” into the Python prompt causes a _____.
A: syntax error

Q: Which Mac application allows you to run commands and execute scripts in a command-line interface?
A: Terminal

Q: Which command will start the Python prompt on your computer?
A: python3

Q: Which command exits from the Python command-line prompt?
A: exit()

Q: If you execute the following expression, what is the output?
>>> 3 + 5 * 2
A: 13

3. Variables and Data Types

Q: When would a removal of white space be problematic?
A: removing the space after the "if" in if x==1

Q: Although Python ignores empty lines, one place where whitespace does make a difference is inside of _____.
A: Special keywords.

Q: Which expression evaluates to 2?
A: 5 % 3

Q: Python treats all numbers the same, regardless of numerical value.
A: FALSE

Q: Which string definition results in an error?
A: 'It's 10am'

Q: Which of these will not output:
I'm learning a lot!
A: print('I'm learning a lot!')

Q: Which character starts a comment in Python?
A: #

Q: What is the output of the following Python code?
first_name = "Jeff"
 #first_name = "Sara"
 print(first_name)
A: Jeff

Q: What will the following code print?
number = 3**2
 Number = 2**3
 print(number)
A: 9

Q: What is the output of this Python code?
first_name = "Jeff"
 first_Name = "Sara"
 print(first_name)
A: Jeff

Q: Which variable name is valid in Python? 3blindmice/$money/account_balance
A: account_balance

Q: Which data type in Python represents a number with a decimal point?
A: Float

Q: How would you fix the following code to return the remainder of 1,000 divided by 300?
1,000 % 300 
A: 1000 % 300

Q: What will the following code print?
variable = "12"
 print(type(variable))
A: str

Q: What operator do you use to assign a value to a variable?
A: =

Q: Which data type is a whole number?
A: int

Q: Which variable name is valid in Python? max distance / break / 1st_rule / speed_limit
A: speed_limit

4. Conditional Code

Q: With if-else statements, we will always execute one of the code blocks depending on the result of the condition test.
A: TRUE

Q: Which operator will you use to return true if two variables are different?
A: !=

Q: Which if-else statement will not produce this output?
is divisible by 3
A:
num = 16
 if num % 3 == 0:
  print("is divisible by 3")
 else:
  print("is not divisible by 3")

Q: Any expression that breaks down to either true or false is called a conditional, or _____.
A: boolean expression

Q: This if-else statement is written in _____.
if "apples" == "apples"
  puts "You're comparing the same thing"
 end
A: Ruby

Q: Which of these is not a relational operator?
A: =

Q: What is the issue with the following code?
number = input("Enter a number: ")
if number == 10:
 print("The number is greater than 10.")
else:
 print("The number is less than 10.") 
A: The conditional statement is checking for equality.

Q: What is the output of this program?
num = 16
if num % 3 == 0:
 print(num, "is divisible by 3")
print("The end")
A: The end

Q: Multiple statements grouped together are called a _____.
A: Block

Q: Which code can you use to print if a test score is a pass or a fail?
A:
if (score>=60):
  print("passed")
 else:
  print("failed")
  
Q: What will the following condition print?
if (num>=0):
  print(num)
 else:
  print(-1 * num)
A: the absolute value of num

Q: What is the output of the following program?
number = 10
if number % 4 == 0:
 print(number, "is divisible by 4")
print("All done")
A: All done

5. Modular Code

Q: Which keyword does Python use to define a function?
A: def

Q: What does the void keyword mean when it is specified before a function definition?
A: The function does not return a value.

Q: What can the following function be used for?
def mystery(x):
  if (x % 2 == 0):
  return("yes")
  else:
  return("no")
A: Checking whether a number is even or odd.

Q: Which is a benefit of functions?
A1: With functions, you don't have to repeat the same code over and over again. 
A2: It's easier to fix a mistake in a function than one copied and pasted in multiple places.

Q: What will the following code print?
def compare():
  print(5, "is greater than", 6)
A: This code will not print anything.

Q: The code that's contained inside of a function is often called the function's legs.
A: FALSE

Q: Why is there no output for this program?
def goodbye():
  print("Bye")
A: We never called the goodbye function.

Q: Given the following code, how would you call the function?
def hello(name):
  print("Hey,", name)
A: hello("John")

Q: What is the issue with this function as defined?
def double():
  print(x*2)
A: The number to double is not received.

Q: Which Python keyword is used to send back values from a function?
A: return

Q: What will the following program print?
def mult_inv(num):
  return 1/num
result=mult_inv(3)
print(result)
A: 0.333333333

Q: What is the output of the following program?

def isEven(num):
  return num % 2 == 0

if isEven(3):
  print("3 is even")
else:
  print("3 is not even") 

A: 3 is not even

Q: Given the first line of the function definition below, which programming language is this?
def factorial(number)
A: Ruby (there is no ':' at the end)

Q: Which value is not an argument to the "hello" function?
def hello(name):
  print("Hey,", name)

hello("John")
hello("Mya")
A: Hey

Q: In this function definition, the variable "name" is _____.
def hello(name):
  print("Hey,", name)
A: A parameter.

X: Further Steps

"Python Essential Training"

Comments