True/False
Vocabulary
Strings
Control
Code (Debugging)
100
Names can begin with a letter, underscore, or a digit - otherwise, the rest of the letters can be a combination of letters, underscores, and digits
FALSE
100
What is the difference between the following: 12 12.0 "12"
What is an int, a float, and a string?
100
True/False - strings can be changed
FALSE - strings are immutable!
100
Write on the board the basic structure of an if-elif-else control
if condition: do something elif condition: do something else: do something
100
Is there anything wrong with this following code: score = int(input("Enter grade score")) if score > 90: print("A") elif score > 80: print("B") elif score > 70: print("C") elif score > 60 print("D") else: print("F")
There is a missing semicolon after 60
200
A statement does not return a value while an expression returns a value.
TRUE
200
A process or a set of rules to be followed in calculations or other problem-solving operations. Or sometimes referred to as a recipe for solving a problem.
What is an algorithm?
200
What are the 5 string methods that manipulate case?
.capitalize(), .title(), .swapcase(), .upper(), .lower()
200
What are the differences between a for loop and a while loop?
A for loop does not need to have the iterator variable initialized, and goes through each part of the sequence/collection. A while loops loops until a condition is false, needs to have the iterator initialized, and must have the condition become false at some point.
200
What is wrong with the following code - if nothing is wrong, then write nothing: #START a = 1000 b = 2 c = 1 while c < 1000: print(a+c) c+=1
Nothing!
300
The .count() method returns the number of times a given character appears in a string
TRUE
300
What is the difference between a while loop, and the for and enumerate loops?
A while loop loops through code as long as the condition is true, a for loop walks through each part of a sequence/collection (like a range or string), and enumerate generates both the index and the item in a sequence/collection
300
What is the output of the code? S = "What's in a name?" print(S[::2]) print(S[2:8])
Wa' nanm? at's i
300
Convert the following for loop into a while loop #Get the sum of all odd numbers from 15 to 50: weirdsum = 0 for i in range(15, 50, 2): weirdsum += i
weirdsum = 0 i = 15 while i < 50: weirdsum+=i i+=2 OR while i < 50: if (i%2 != 0) weirdsum+=i i+=1
300
What is wrong with the following code - if nothing, then say nothing! Igotbills = "To pay" print(Igotbills) Igotbills.reassign("I gotta pay") print(Igotbills) Igotbills.reassign("I gotta pay") print(Igotbills)
There is no reassign method
400
An algorithm must be detailed, effective, specific to its behavior, and specific for the coding language that it's written for.
FALSE
400
Fill in the following matrix: -------------------------------------------------------------------- mode |how it opens the file |if file exists| if file doesn't exist -------------------------------------------------------------------- 'r' | | | --------------------------------------------------------------------'w' |write only | | -------------------------------------------------------------------- | | |creates new file --------------------------------------------------------------------
Check page 231 of the textbook!
400
Given the string 'abcdefghij', write code that will produce the following: 'jihgfedcba' 'adgj' 'igeca'
print(S[::-1]) print(S[::3]) print(S[-2::-2])
400
What is missing from this while-try-except loop? #Get number from user while True: try: num = input("Enter a number") num = int(num) except ValueError: print("You need to enter in a number")
You need a break after num=int(num), or else this becomes an endless loop
400
What is wrong with this code - if nothing is wrong, say "Nothing!" #START OF CODE pie = 3.14156 print(pie) print("{} is the exact number".format(math.pi))
math.pi is in the math module, which has not been imported
500
There are two different types of string functions that return a string and those that return True/False. There are three total answers: 1.What is the general form of string methods that return True/False? 2. What is the string method that returns True/False based on the string's beginning? 3. What is the string method that returns True/False based on the strong's end
1. Any string that begins with 'is' 2. startswith() 3. endswith()
500
#Not a Vocabulary, but this is another string question! Create code that will prompt the user for two words (one verb and one noun), and replace the following string with them: long_string = "To VERB or not to VERB: that is the NOUN"
verb = input("Enter a verb") noun = input("Enter a noun") long_string.replace("VERB",verb,2) long_string.replace(""NOUN",noun)
500
Write code that prompts for two strings, compares them, and then prints the smaller string
Various answers
500
What is the value of t after this loop has executed? t = 0 for i in range(0,15,2): t += i if t < 10: t+=15 elif t > 20: t+=30
What is the value of t after this control executes?
500
There are a total of three errors with this code - what are they? j = 20 k = "40" c = 20 m= "c"*200 print(m[:c]) for char in m; print(char) i = 320 while i < k: print(k) print(d) i-=2
1. Missing colon in the for loop 2. D is not defined 3. i