MTA EXAM QUESTIONS AND ANSWERS
HOW TO USE THE DIFFERENT FUNCTIONS WITHIN THE RANDOM LIBRARY -
Correct Answers -use:
from random import ___
use from random import randint when wanting to generate random integers
use
from random import randrange, lets you import a range of numbers and gives you a
random number within the numbers given. Ex: (1,6) -- gives a random number from 1 to
5
use
from random import rand
When declaring variables in Python, a data type must be specified
True of False - Correct Answers -false
Python makes the distinction between integers and floating variables.
True of False - Correct Answers -True
When setting a boolean variable, the value must start with a capital letter
True of False - Correct Answers -True, meaning it must begin with True or False
what are concatenation symbols - Correct Answers -commas if different data type and
plus signs if they are the same data type
improper syntax of way the varibles are written when declared - Correct Answers -
spaces and dashes should not be used when declaring variables
evaluate this statement:
a =5
b=3
b=a - Correct Answers -since b = a then a == b and b = 5 not 3 anymore, so a is b
, what keywork in python checks to seee if a number or text is available - Correct
Answers -the keyword "in" and then the name of the variable
code to print our letter grades of students - Correct Answers -def grades():
if score >=90: grade = 'A'
if score >=80: grade = 'B'
if score >=70: grade = 'C'
else:
grade = 'F'
WHAT keyword is used as a placeholder for a conditional result? - Correct Answers -
pass
the while keyword starts a ... - Correct Answers -loop
what does the continue keyword do - Correct Answers -skips a turn in the loop
difference between \ , \n ,\\, and \t - Correct Answers -the symbol \ tells python to
continue the statement on the next line
\n tell python to print a new line
\t tells python to insert a tab
\\ tells python to use the \ character
how to open a file and read it // without being able to write in it - Correct Answers -
variableName = open ('fileName', "r")
newVariableName = variableName.read()
print (newVariableName)
how to free up the memory that a file has been using after opening a file - Correct
Answers -using the example below:
variableName = open ('fileName', "r")
newVariableName = variableName.read()
print (newVariableName)
to close:
variableName.close()
How to get this file to only read the first line:
workFile = open('work.txt', 'r')
workFileFirstLine = __________?
print (workFileFirstLine) - Correct Answers -workFile.readline()
HOW TO USE THE DIFFERENT FUNCTIONS WITHIN THE RANDOM LIBRARY -
Correct Answers -use:
from random import ___
use from random import randint when wanting to generate random integers
use
from random import randrange, lets you import a range of numbers and gives you a
random number within the numbers given. Ex: (1,6) -- gives a random number from 1 to
5
use
from random import rand
When declaring variables in Python, a data type must be specified
True of False - Correct Answers -false
Python makes the distinction between integers and floating variables.
True of False - Correct Answers -True
When setting a boolean variable, the value must start with a capital letter
True of False - Correct Answers -True, meaning it must begin with True or False
what are concatenation symbols - Correct Answers -commas if different data type and
plus signs if they are the same data type
improper syntax of way the varibles are written when declared - Correct Answers -
spaces and dashes should not be used when declaring variables
evaluate this statement:
a =5
b=3
b=a - Correct Answers -since b = a then a == b and b = 5 not 3 anymore, so a is b
, what keywork in python checks to seee if a number or text is available - Correct
Answers -the keyword "in" and then the name of the variable
code to print our letter grades of students - Correct Answers -def grades():
if score >=90: grade = 'A'
if score >=80: grade = 'B'
if score >=70: grade = 'C'
else:
grade = 'F'
WHAT keyword is used as a placeholder for a conditional result? - Correct Answers -
pass
the while keyword starts a ... - Correct Answers -loop
what does the continue keyword do - Correct Answers -skips a turn in the loop
difference between \ , \n ,\\, and \t - Correct Answers -the symbol \ tells python to
continue the statement on the next line
\n tell python to print a new line
\t tells python to insert a tab
\\ tells python to use the \ character
how to open a file and read it // without being able to write in it - Correct Answers -
variableName = open ('fileName', "r")
newVariableName = variableName.read()
print (newVariableName)
how to free up the memory that a file has been using after opening a file - Correct
Answers -using the example below:
variableName = open ('fileName', "r")
newVariableName = variableName.read()
print (newVariableName)
to close:
variableName.close()
How to get this file to only read the first line:
workFile = open('work.txt', 'r')
workFileFirstLine = __________?
print (workFileFirstLine) - Correct Answers -workFile.readline()