• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 13 pages
Exam (elaborations)

Python Exam Chapters 1-5 Exam Questions Correctly Answered.

Document preview thumbnail
Preview 2 out of 13 pages

Python Exam Chapters 1-5 Exam Questions Correctly Answered. Which of the following are operators, and which are values? * 'hello' -88.8 - / + 5 - CORRECT ANSWER The operators are +,-,*,and /. The values are 'hello' ,-88.8, and 5. Which of the following is a variable , and which is a string ? spam 'spam' - CORRECT ANSWER The variable is spam; the string is 'spam'. Strings always start and end with quotes. Name three data types. - CORRECT ANSWER The three data types are integers, floating point numbers, and strings. What is an expression made up of ? What do all expressions do ? - CORRECT ANSWER An expression is a combination of values and operators. All expressions evaluate (that is, reduce) to a single value. This chapter (1) introduced assignment statements, like spam = 10. What is the difference between an expression and a statement? - CORRECT ANSWER An expression evaluates to a single value. A statement does not. What does the variable bacon contain after the following code runs? bacon = 20 bacon + 1 - CORRECT ANSWER The bacon variable is set to 20. The bacon + 1 expression does not reassign the value in bacon (that would need an assignment statement: bacon = bacon + 1). What should the following two expressions evaluate to ? 'spam' + 'spamspam' 'spam' * 3 - CORRECT ANSWER Both expressions evaluate to the string 'spamspamspam'. Why is egg a valid variable name while 100 is invalid ? - CORRECT ANSWER Variable names cannot begin with a number. What three functions can be used to get the integer, floating-point number, or string version of a value ? - CORRECT ANSWER The int(), float(), and str() functions will evaluate to the integer, floating-point number, and string versions of the value passed to them. Why does this expression cause an error ? How can you fix it ? 'I have eaten' + 99 + 'burritos' . - CORRECT ANSWER The expression causes an error because 99 is an integer, and only strings can be concatenated to other strings with the + operator. The correct way is i have eaten ' + str(99) + ' burritos '. What are the two values of the Boolean data type? How do you write them? - CORRECT ANSWER True and False, using capital T and F, with the rest of the word in lowercase. What are the three Boolean operators? - CORRECT ANSWER and, or, and not. Write out the truth tables of each Boolean operator (that is, every possible combination of Boolean values for the operator and what they evaluate to). - CORRECT ANSWER True and True is True. True and False is False. False and True is False. False and False is False. True or True is True. True or False is True. False or True is True. False or False is False. not True is False. not False is True. What do the following expressions evaluate to ? (5 4) and (3 == 5) not (5 4) (5 4) or (3 == 5) not ((5 4) or (3 == 5)) (True and True) and (True == False) (not False) or (not True) - CORRECT ANSWER False False True False False True What are the six comparison operators ? - CORRECT ANSWER ==, !=, ,,=,and = What is the difference between the equal to operator and the assignment operator ? - CORRECT ANSWER == is the equal operator to operator that compares two values and evaluates to a Boolean, while = is the assignment operator that stores a value in a variable. Explain what a condition is and where you would use one. - CORRECT ANSWER A condition is an expression used in a flow control statement that evaluates to a Boolean value. Identify the three blocks in this code: spam = 0 if spam == 10: print('eggs')

Content preview

Python Exam Chapters 1-5 Exam
Questions Correctly Answered.

Which of the following are operators, and which are values?

*

'hello'

-88.8

-

/

+

5 - CORRECT ANSWER The operators are +,-,*,and /. The values are 'hello' ,-88.8, and 5.



Which of the following is a variable , and which is a string ?

spam

'spam' - CORRECT ANSWER The variable is spam; the string is 'spam'. Strings always start and end with
quotes.



Name three data types. - CORRECT ANSWER The three data types are integers, floating point numbers,
and strings.



What is an expression made up of ? What do all expressions do ? - CORRECT ANSWER An expression is a
combination of values and operators. All expressions evaluate (that is, reduce) to a single value.



This chapter (1) introduced assignment statements, like spam = 10. What is the difference between an
expression and a statement? - CORRECT ANSWER An expression evaluates to a single value. A
statement does not.



What does the variable bacon contain after the following code runs?

bacon = 20

, bacon + 1 - CORRECT ANSWER The bacon variable is set to 20. The bacon + 1 expression does not
reassign the value in bacon (that would need an assignment statement: bacon = bacon + 1).



What should the following two expressions evaluate to ?

'spam' + 'spamspam'

'spam' * 3 - CORRECT ANSWER Both expressions evaluate to the string 'spamspamspam'.



Why is egg a valid variable name while 100 is invalid ? - CORRECT ANSWER Variable names cannot begin
with a number.



What three functions can be used to get the integer, floating-point number, or string version of a value ?
- CORRECT ANSWER The int(), float(), and str() functions will evaluate to the integer, floating-point
number, and string versions of the value passed to them.



Why does this expression cause an error ? How can you fix it ?

'I have eaten' + 99 + 'burritos' . - CORRECT ANSWER The expression causes an error because 99 is an
integer, and only strings can be concatenated to other strings with the + operator. The correct way is i
have eaten ' + str(99) + ' burritos '.



What are the two values of the Boolean data type? How do you write them? - CORRECT ANSWER True
and False, using capital T and F, with the rest of the word in lowercase.



What are the three Boolean operators? - CORRECT ANSWER and, or, and not.



Write out the truth tables of each Boolean operator (that is, every possible combination of Boolean
values for the operator and what they evaluate to). - CORRECT ANSWER True and True is True.

True and False is False.

False and True is False.

False and False is False.

True or True is True.

True or False is True.

False or True is True.

Document information

Uploaded on
April 5, 2025
Number of pages
13
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$12.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ROSEGRADES
3.4
(35)
Sold
236
Followers
87
Items
12121
Last sold
4 weeks ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions