What is the output after the code runs?
x="six"
x=7
x="eight"
print(x)
eight
What datatype does the input Function return?
String
count = 1
while count >= 1:
print("loop")
count +=1
forever loop
What is the index of the first character in a list?
0
What type of loop should you use to repeat a code process as long as a condition resolves as `True`?
While
The following code produces what type of error?
numerator = 4
denominator = 0
answer= numerator/denominator
print("The answer is" +str(answer))
RunTime Error
1. greet(name)
2. name = input("enter your name: ")
3. greet(name)
4. def greet(person):
5. print("Hi,", person)
6. greet(name)
Which line or lines need to be removed from the above code so the program prints a greeting without error?
Lines 1 and 3
time = 3
while True:
print('time is', time)
if time == 3:
time = 4
else:
break
"time is 3" & "time is 4"
Write the code that will place another "2" integer to the end of the following list?
numbers = [1, 1, 2]
numbers.append(2)
What function can you use to test whether an absolute or relative path to a folder is valid?
os.path.exists(path)
def add_nums(num = 1):
return num + num
What is the correct output of calling the function above using the following code:
print(add_nums(25))
50
What is the output of the following code?
gpa = 3.62
print("Your GPA is", gpa, ".")
Your GPA is 3.62 .
Write the code that will print the word "tac", given the following variable declaration?
word = "cat"
print(word[::-1])
What is the result of the following code?
numbers = [2, 3, 2]
total = 0
while numbers:
total += numbers.pop()
numbers is an empty list and total is 7
Create the tuple, T, with one element (25).
T = (25,)
What is the output of the following code?
name = 16
if name.startswith("n"):
print("Hello")
else:
print("Goodbye")
An error message
What is the value of x after the following code is run?
x = 2
y = 1
x += y + 1
4
Write the Python code that results in output of a sorted scores list WITHOUT changing the original scores list below?
scores = [ 0, 5, 2, 11, 1, 9, 7]
print(sorted(scores))
After we open a file (first_test) using:
test1 = open('test1.txt', 'r')
we can read the file into memory with what Python code?
test_data = test1.read()
What is the result of the following code?
(Name, Grade) = ("Anne", 95)
print(Name, Grade)
Anne 95
PriNt("Hello World!") will not output the message "Hello World!".
What type of error will it result in?
answer = input("enter your answer: ")
print("You entered " + answer)
If user input is 38, what is the output of the above code?
You entered 38
Write the code that will delete the "5" in the following numbers list?
numbers = [7, 1, 5, 8, 0]
del numbers[2]
To move the pointer in an open file to the first character, what should you use?
.seek(0)
What is the output of the following code?
year = 2017
price = 2.42011
print('The national average gas price in %i was $ %3.2f' % (year, price))
he national average gas price in 2017 was $ 2.42