Quiz 2 Flashcards
What is a Boolean Expression?
A bool is a data type. An expression that is tested to see whether it is true or false by an if statement in Python.
What is a control structure?
A control structure allows us to control the order in which a set of statements executes
What is a sequence structure?
a set of statements that execute in the order that they appear.
What is a dual alternative decision structure? How does it work? What statment do you use in Python to write a dual alternative decision structure?
if else clause. One taken if the condition is true and the other if the condition is false.
Write a snippet of code that will compare two strings. The program will print “They are the same” if the strings are identical. The program will print “They are not the same.” if the strings are different.
P = "something" Q = "something" if (P == Q): print ("They are the same.") else: print("They are the same.")
What is a compound Boolean expression?
( P==Q and R==S)
What will the program display? s1 = "Dillon" s2= "Butte" if s1 > s2: print (s2) print (s1) else: print (s1) print (s2)
Butte
Dillon
Simplify:
Not (num >0 and temp <=0)
num <= 0 or temp >0
Simplify:
not (sum<5 or not (num>0)
sum >=5 and num>0
simplify:
not(num>0 and sum >0)
num<= 0 and sum <=0
simplify:
not( X and not Y) or (X and Y)
(not X or Y) and (X or Y)
What is a decision structure:
specific action(s) performed only if a condition exists
write an if statement that assigns 20 to the variable y and assigns 40 to the variable z if the variable x is greater than 100
if x > 100:
y = 20
Z = 40
What is a single alternative decision structure:
provides only one alternative path of execution
What is a relational operator?
determines whether a specific relationship exists between two values Example: greater than (>)