Chapter 3

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 27

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

28 Terms

1

What is a control structure?

A logical design that controls the order in which a set of statements execute.

New cards
2

What is a decision structure?

It is a program structure that can execute a set of statements only under certain circumstances.

New cards
3

What is a single alternative decision structure?

Provides a single alternative path of execution. If the condition that is being tested is true, the program takes the alternative path.

New cards
4

What is a Boolean expression?

An expression that can be evaluated as either true or false.

New cards
5

What types of relationships between values can you test with relationship operators?

You can determine whether one value is greater than, less than, greater than or equal to, less than or equal to, equal to, or not equal to another value.

New cards
6

Write an if statement that assigns 0 to x if y is equal to 20.

if y == 20:

x=0

New cards
7

Write an if statement that assigns 0.2 to commissionRate if sales is greater than or equal to 10000.

if sales >= 10000:

  • commissionRate = 0.2

New cards
8

How does a dual alternative decision structure work?

It has two possible paths of execution; one path is taken if a condition is true, and the other path is taken if the condition is false.

New cards
9

What statement do you use in Python to write a dual alternative decision structure?

if-else

New cards
10

When you write an if-else statement, under what circumstances do the statements that appear after the else clause execute?

When the condition is false.

New cards
11

What would the following code display?

if ‘z’ < ‘a’:

  • print (‘z is less than a.’)

else:

  • print (‘z is not less than a.’)

z is not less than a.

New cards
12

What would the following code display?

s1= ‘New York’

s2=’Boston’

if s1 > s2:

  • print (s2)

  • print (s1)

else:

  • print (s1)

  • print (s2)

Boston

New York

New cards
13

Convert the following code to an if-elif-else statement:

if number == 1:

  • print (‘One’)

else

  • if number == 2:

    • print (‘Two’)

  • else:

    • if number == 3:

      • print (‘Three’)

    • else:

      • print (‘Unknown’)

if number == 1

  • print (‘One’)

elif number == 2:

  • print(‘Two’)

elif number == 3:

  • print (‘Three’)

else:

  • print (‘Unknown’)

New cards
14

What is a compound Boolean expression?

It is an expression that is created by using a logical operator to combine two Boolean subexpressions.

New cards
15

The following truth table shows various combinations of the values true and false connected by a logical operator. Complete the table by circling T or F to indicate whether the result of such a combination is true or false.

  • Page 139 & Answer Key

  • F

  • T

  • F

  • F

  • T

  • T

  • T

  • F

  • F

  • T

New cards
16

Assume the variables a= 2, b=4, and c=6. Circle T or F for each of the following conditions to indicate whether its value is true or false.

  • a==4 or b >2

  • 6<= c and a >3

  • 1 != b and c != 3

  • a >= -1 or a <= b

  • not (a > 2)

  • T

  • F

  • T

  • T

  • T

New cards
17

Explain how short-circuit evolution works with the and and or operators.

  • The and operator: if the expression on the left side of the and operator is false, the expression on the right side will not be checked

  • The or operator: If the expression on the left side of the or operator is true, the expression on the right side will not be checked.

New cards
18

Write an if statement that displays the message “The number is valid” if the value referenced by speed is within the range 0 through 200.

if speed >= 0 and speed <= 200:

  • print (‘The number is valid’)

New cards
19

Write an if statement that displays the message “The number is not valid” if the value referenced by speed is outside the range 0 through 200.

if speed < 0 or speed > 200:

  • print(‘The number is not valid’)

New cards
20

What values can you assign to a bool variable?

True or False

New cards
21

What is a flag variable?

A variable that signals when some condition exists in the program

New cards
22

How do you get the turtle’s X and Y coordinates?

You can use the turtle.xcor() and turtle.ycor() functions.

New cards
23

How would you determine whether the turtle’s pen is up?

You would use the not operator with the turtle.isdown() function, like this:

if turtle.isdown():

  • statement

New cards
24

How do you get the turtle’s current heading?

You use the turtle.heading() function.

New cards
25

How do you determine whether the turtle is visible?

You can use the turtle.isvisible() function.

New cards
26
  • How do you determine the turtle’s pen color?

  • How do you determine the current fill color?

  • How do you determine the current background color of the turtle’s graphics window?

  • You use the turtle.pencolor() function to determine the pen color.

  • You use the turtle.fillcolor() function to determine the current fill color.

  • You use the turtle.bgcolor() function to determine the current background color of the turtle’s graphics window.

New cards
27

How do you determine the current pen size?

You use the turtle.pensize() function.

New cards
28

How do you determine the turtle’s current animation speed?

You use the turtle.speed() function.

New cards
robot