Adv Computer Science Sem 1 Practice: Chapters 1-3
Which of the following lines is a valid Python comment?
# Let me explain
What text is displayed on output by the following statement? print(str.format("#{0:4}#", "dog") ) dog #dog# #dog # ##
#dog #
Which symbol is used to combine (concatenate) two strings together into a single value?
+ (plus sign)
What file extension is normally given to Python source code?
.py
How many parameters are you passing into the print() function in the following statement? print("My final answer is: " + str(answer) )
1
What would be displayed on the output panel when the following code is run? data = 100 print(data)
100
Which of the following variable names are invalid? Look_at_me All of these are valid 123LookAtMe LookAtMe123
123LookAtMe
How many lines of output will be shown from the following code? print("Line 1", end = " ") print("Line 2") print("Line 3", end = " ")
2
How many major releases have there been of the Python language?
3
which version of python are you learning in this course
3
Which of the following values is not a valid integer?
5.5
What will be stored in the "answer" variable after the following code runs? part1 = 4part2 = 2answer = part1 * part2
8
Which of the following best describes a variable?
A named area in computer memory that holds a value
Which of the following best describes the Python Software Foundation?
A non-profit organization created in 2001 to maintain Python
When you use the print() statement to automatically concatenate multiple parameters together, which of the following statements is true?
A space will be automatically added to separate each part within the output string
If the user enters "18" in response to an input() question, what kind of data is returned?
A string containing "18"
What string value is stored in the result variable by the following statement? result = str.format("{1} {0} is really Superman", "Kent", "Clark")
Clark Kent is really Superman
How do you safely break a long Python statement across multiple lines?
Add a backslash (\) at the end of each line that has more to follow on the next line
Why did Guido van Rossum create the Python language?
As a hobby project over a Christmas break
Which of the following best describes the input() function?
Asks the user a question and returns a string answer
What is wrong with the following code? result = 10 * 10print("The answer is " + result)
Error - Python can't convert the integer result to a string automatically when concatenating
How long will the input() function wait for user input?
Forever, until the user enters a value and hits "Enter"
Which of the following steps must be taken to create and run Python programs on your own computer?
Install the Python interpreter
Which of the following best describes the input() parameter?
It contains a text prompt for the user to enter a value
How do you change the data type of a variable?
Just assign a new value to the variable, and the type is automatically changed
The Python language was named after what thing?
Monty Python's Flying Circus TV show
What is the displayed output when the following code is run? myGPA = 3.5print("My GPA is", str(myGPA))
My GPA is 3.5
What is the output when the following statements are run? favoriteColor = "purple"print("My favorite color is", favoriteColor)
My favorite color is purple
What value will be stored in the "greeting" variable after the following statement runs? greeting = "Nice" + "to" + "meet" + "you"
Nicetomeetyou
If you concatenate strings together with the plus sign (+), which of the following statements is true?
No spaces will be added to separate the parts within the output string
Which of the following best describes how Python statements are executed?
One at a time, from top to bottom
What is the output from the following statement? print(str.format("Sale Price: ${0:6,}",1500))
Sale Price: $ 1,500
What is the printed output from the following statement? print("Testing" + "Testing")
TestingTesting
What happens if you write code that does not follow Python syntax rules?
The program will not run, and you will see an error message instead
How does Python use indentation (spacing of statements to the right)?
To identify blocks of code that belong together
What is the purpose of leaving comments in your source code?
To make the code easier for human readers to understand
What is the purpose of the first parameter in the str.format() function?
To set up the overall structure of the output, including placeholders for other data
Which of the following is an advantage to using our online Python engine?
You don't need to install Python on your local computer
What will happen when the following statements run? value = "orange" result = int(value)
You will see a ValueError message due to invalid int() input
What character do you place at the end of a line to break a long statement across multiple lines?
a backslash (\)
Which of the following statements will convert a string stored in "inputResults" to an integer variable called "age"?
age = int(inputResults)
What is wrong with the following code? ageInYears = input("How old are you? ")ageInDays = ageInYears * 365
ageInYears is a string and can't be used in a mathematical expression
Python will run on which of the following computer systems?
all of these are true
What does a data type say about a value? The types of operations that can be done on the data The kind of data that can be stored in the value All of these are true The amount of computer memory needed to hold the data
all of these are true
What kinds of things can you find at the www.python.org website? -All of these are true -Python success stories and documentation -Python blogs and community events -Python updates and downloads
all of these are true
Which of the following approaches can you use to run Python programs? -Run Python from the command line -Use an Integrated Development Environment (IDE) -All of these are true -Use the online python engine within the course lesson pages
all of these are true
which of the following is true about our online python engine found within your lessons?
all of these are true
Which of the following variable names are valid in Python? All of these are valid TESTING testing123 testing_123
all of thesea re valid
Which of the following statements will successfully prompt the user for input and store the result in the "answer" variable?
answer = input("What is your quest?")
Which of the following statements will successfully combine the string value stored in "myString" and the numeric value stored in "myNum" and store the string result in "answer"? answer = myString * parse(myNum) answer = myString + myNum answer = convert("myString") + myNum answer = myString + str(myNum)
answer = myString + str(myNum)
Where can you start a Python comment in your source code? Both of these are true Neither of these is true To the right of an existing Python statement At the beginning of a new line
both of these are true
What will be stored in the "description" variable after the following statements run? value = 3.14description = type(value)
class 'float'
Which of the following statements will ask the user for a favorite color and store the answer in the "color" variable?
color = input("What is your favorite color? ")
What do programmers call the process of joining together two strings?
concatenation
Which function would you use to convert a string value to a floating point value?
float()
Which data type would best hold the numeric value 1.732?
floating point
In what order will Python execute statements in your source file?
from top to bottom
who created python
guido van rossum
If the "heightString" variable contains the string "6.2", which of the following statements would convert that to a floating point value stored in a variable named "height"?
height = float(heightString)
which of the following steps is required in order to run python on your local computer?
install the python interpreter
what kind of programming language is python? - compiled - imaginary - interpreted - binary
interpreted
Which of the following terms best describes the Python component that translates Python source code into program output?
interpreter
What is the displayed output when the following statement is run? print("phone","number",sep="#") phone number "phone" on one line and "number" on the next phone#number phonenumber
phone#number
Based on best practice rules for naming variables, which of the following variable names would be best to hold a value containing a player's score?
playerScore
Which of the following statements will print a message and NOT automatically advance to the next line for the next printed output?
print("Stay here", end=" ")
Which Python function will display a line of text on the screen?
print()
What happens when you call print() and provide more than one parameter, separated by commas?
print() will automatically concatenate them together into a single output string
Which of the following two statements about the print() function are true? Both of these are true print() with multiple parameters will automatically convert all values to strings and join them together with a space print() with a single string parameter will display the exact string that you pass in Neither of these is true
print() with a single string parameter will display the exact string that you pass in
Which of the following statements will successfully display the value 1.732 to the screen?
print(1.732)
Given a variable named "mystery", which of the following statements will display the data type of that variable?
print(type(mystery))
Why is Python a good language for beginning programmers to learn?
python is free and easy to use
Which of the following statements will add 10 to the value in the "mystery" variable and store the answer in the "result" variable?
result = 10 + mystery
which of the following is the best description of an integrated development environment (IDE)?
software that helps you create and run code
python programs that you write start out in which form? - interpreted output - punch cards - source code - binary executable
source code
Which Python function can you use to convert a numeric data type into a string?
str()
What type of data does the input() function return?
string
Which of the following variable names are invalid in Python? testing#123 testing 123 All of these are invalid 123_testing
testing 123
which organization manages the python language today?
the python software foundation
Which of the following statements correctly assigns the value 42 to a variable named "theAnswer"?
theAnswer = 42
What do we call an area in computer memory that holds a named value?
variable
How does Python know you've reached the end of a code statement?
you hit the "enter" key to move to the next line
How would you create a str.format() placeholder in the format string to ensure at least 20 characters minimum width for the first value?
{0:20}
Which of the following placeholders in a str.format() format string would display a floating point value, centered in a 15-character wide field?
{0:^15f}
Which of the following placeholder expressions in a str.format() format string will limit (truncate) the width of an output value to 10 characters?
{:5.10}
