Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Examen

Python Programming Exam Chapters 1-5 Questions With Correct Answers

Note
-
Vendu
-
Pages
14
Qualité
A+
Publié le
07-02-2024
Écrit en
2023/2024

Which of the following are operators, and which are values? * 'hello' -88.8 - / + 5 - 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' - Answer The variable is spam; the string is 'spam'. Strings always start and end with quotes. Name three data types. - Answer The three data types are integers, floating point numbers, and strings. What is an expression made up of ? What do all expressions do ? - 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? - 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 - 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 - Answer Both expressions evaluate to the string 'spamspamspam'. Why is egg a valid variable name while 100 is invalid ? - 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 ? - 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' . - 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? - Answer True and False, using capital T and F, with the rest of the word in lowercase. What are the three Boolean operators? - 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). - 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) - Answer False False True False False True What are the six comparison operators ? - Answer ==, !=, ,,=,and = What is the difference between the equal to operator and the assignment operator ? - 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. - 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') if spam 5: print('bacon') else: print('ham') print('spam') print('spam') - Answer The three blocks are everything inside the if statement and the lines print('bacon') and print('ham'). print('eggs') if spam 5: print('bacon') else: print('ham') print('spam') Write code that prints Hello if 1 is stored in spam, prints Howdy if 2 is stored in spam, and prints Greetings! if anything else is stored in spam. - Answer if spam == 1: print('Hello') elif spam == 2: print('Howdy') else: print('Greetings!') What keys can you press if your program is stuck in an infinite loop ? - Answer Press ctrl-C to stop a program stuck in an infinite loop. What is the difference between break and continue ? - Answer The break statement will move the execution outside and just after a loop. The continue statement will move the execution to the start of the loop. What is the difference between range(10), range(0,10), and range(0,10,1) in a for loop ? - Answer They all do the same thing. The range(10) call ranges from 0 up to (but not including) 10, range(0,10) explicitly tells the loop to start at 0 , and range (0,10,1) explicitly tells the loop to increase the variable by 1 on each iteration. Write a short program that prints the numbers 1 to 10 using for loop. Then write an equivalent program that prints the numbers 1 to 10 using a while loop. - Answer for i in range (1,11): print(i) and: i = 1 while i = 10: print(i) i = i + 1

Montrer plus Lire moins
Établissement
Python Programming
Cours
Python Programming









Oups ! Impossible de charger votre document. Réessayez ou contactez le support.

École, étude et sujet

Établissement
Python Programming
Cours
Python Programming

Infos sur le Document

Publié le
7 février 2024
Nombre de pages
14
Écrit en
2023/2024
Type
Examen
Contenu
Questions et réponses

Sujets

9,80 €
Accéder à l'intégralité du document:

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Faites connaissance avec le vendeur

Seller avatar
Les scores de réputation sont basés sur le nombre de documents qu'un vendeur a vendus contre paiement ainsi que sur les avis qu'il a reçu pour ces documents. Il y a trois niveaux: Bronze, Argent et Or. Plus la réputation est bonne, plus vous pouvez faire confiance sur la qualité du travail des vendeurs.
Grademasters West Virginia University
S'abonner Vous devez être connecté afin de pouvoir suivre les étudiants ou les formations
Vendu
115
Membre depuis
3 année
Nombre de followers
68
Documents
2599
Dernière vente
1 mois de cela
Grademasters

3,8

46 revues

5
20
4
9
3
11
2
2
1
4

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions