MSBC 5070 (Midterm Review) Flashcards
Fill in the blanks to complete the code that will ask a user for their name and store the result in a variable called, name.
xxxxx=xxxxxx(“What is your name?”)
name=input
What does the expression, 9 % 3, evaluate to?
0
What is the correct Python function to convert a value to a string
str()
Write the code to import the random module:
import random
Is the following an assignment or expression: eggs=2
assignment
Is the following an assignment or expression: 2
expression
What does Python return when the following function is executed?
str(245)
‘245’
False and True evaluates to:
False
True or False evaluates to:
True
Write code that uses a string method to return a Boolean value indicating whether or not a variable, name, is in Title Case format.
name.istitle()
What does Python return when the following function is executed?
int(‘245’)
245
After the following two lines of python code runs, what is the value of the revenue variable?
revenue = 1000
revenue + 10
1000
Given the following variable:
studentGrades = [10, 10, 10, 85, 85, 90, 100, 100,100]
Write the sub list that would be returned by the following code:
studentGrades[2:5]
10,85,85
What is the % operator in Python?
Modulus
What is the correct Python function to convert a value to a floating-point number.
float()
By default, the while loop is an:
A.Entry controlled loop
B.Exit controlled loop
A.
Fill in the blanks to complete the python code that will find the remainder when 23 is divided by 3:
23%3
Fill in the blanks to complete the code that uses a string method to convert a variable, name, to upper case.
name.upper()
Consider the following code segment:
theSum = 0.0
while True:
number = input("Enter a number: ") if number == "": break theSum += float(number)
How many times will the loop run?
A. None
B. At least Once
C. Infinite while loop
D. None of the above
B.
True and True and True and False evaluates to:
False
Given the following list variable:
studentGrades = [10, 10, 10, 85, 85, 90, 100, 100,100]
What would be returned by the following code:
studentGrades[5]
90
In order to prompt for and get a user’s input via the keyboard, which Python function can be used?
input()
What can be provided as an argument within the parentheses of the input() function?
A. a string
B. an integar
C. a float
D. a comment
A.