2. Variables, Expressions, and Statements Flashcards

1
Q

assignment

A

A statement that assigns a value to a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

concatenate

A

To join two operands end to end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

comment

A

Information in a program that is meant for other programmers (or anyone reading the source code) and has no effect on the execution of the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

evaluate

A

To simplify an expression by performing the operations in order to yield a single value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

expression

A

A combination of variables, operators, and values that represents a single result value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

floating point

A

A type that represents numbers with fractional parts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

integer

A

A type that represents whole numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

keyword

A

A reserved word that is used by the compiler to parse a program; you cannot use keywords like if, def, and while as variable names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

mnemonic

A

A memory aid. We often give variables mnemonic names to help us remember what is stored in the variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

modulus operator

A

An operator, denoted with a percent sign (%), that works on integers and yields the remainder when one number is divided by another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

operand

A

One of the values on which an operator operates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

operator

A

A special symbol that represents a simple computation like addition, multiplication, or string concatenation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

rule of precedence

A

The set of rules governing the order in which expressions involving multiple operators and operands are evaluated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

statement

A

A section of code that represents a command or action. So far, the statements we have seen are assignments and print expression statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

string

A

A type that represents sequences of characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

type

A

A category of values. The types we have seen so far are integers (type int), floating-point numbers (type float), and strings (type str).

17
Q

value

A

One of the basic units of data, like a number or string, that a program manipulates.

18
Q

variable

A

A name that refers to a value.

19
Q

Write a program that uses input to prompt a user for their name and then welcomes them.

Enter your name: Chuck
Hello Chuck

A
  1. question = ‘Enter your Name : ‘
  2. name = input(question)
  3. print(‘Hello’,name)
20
Q

Write a program to prompt the user for jours and rate per hour to compute gross pay.

Enter Hours: 35
Enter Rate: 2.75
Pay: 96.25

We won’t worry about making sure our pay has exactly two digits after the decimal place for now. If you want, you can play with the built-in Python round function to properly round the resulting pay to two decimal places.

A

hours = int(input(‘Enter Hours: ‘))
rate = float(input(‘Enter Rate: ‘))
gross_pay = hours * rate
print(‘Pay:’,gross_pay)

21
Q

Assume that we execute the following assignment statements:

width = 17
height = 12.0

For each of the following expressions, write the value of the expression and the type (of the value of the expression).

  1. width//2
  2. width/2.0
  3. height/3
  4. 1 + 2 * 5

Use the Python interpreter to check your answers.

A
  1. width = 17
  2. height = 12.0
  3. print(width//2)
  4. print(width/2.0)
  5. print(height/3)
  6. print(1 + 2 * 5)
22
Q

Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.

A
  1. Celsius = float(input(‘Enter Celsius temperature: ‘))
  2. Fahrenheit = ((Celsius * 9) / 5) + 32
  3. print(‘Fahrenheit:’,Fahrenheit)