Geschrieben von Student*innen, die bestanden haben Sofort verfügbar nach Zahlung Online lesen oder als PDF Falsches Dokument? Kostenlos tauschen 4,6 TrustPilot
logo-home
Prüfung

Python Programming Exam Chapters 1-5 Questions With Correct Answers

Bewertung
-
Verkauft
-
seiten
14
Klasse
A+
Hochgeladen auf
07-02-2024
geschrieben in
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

Mehr anzeigen Weniger lesen
Hochschule
Python Programming
Kurs
Python Programming









Ups! Dein Dokument kann gerade nicht geladen werden. Versuch es erneut oder kontaktiere den Support.

Schule, Studium & Fach

Hochschule
Python Programming
Kurs
Python Programming

Dokument Information

Hochgeladen auf
7. februar 2024
Anzahl der Seiten
14
geschrieben in
2023/2024
Typ
Prüfung
Enthält
Fragen & Antworten

Themen

9,80 €
Vollständigen Zugriff auf das Dokument erhalten:

Falsches Dokument? Kostenlos tauschen Innerhalb von 14 Tagen nach dem Kauf und vor dem Herunterladen kannst du ein anderes Dokument wählen. Du kannst den Betrag einfach neu ausgeben.
Geschrieben von Student*innen, die bestanden haben
Sofort verfügbar nach Zahlung
Online lesen oder als PDF

Lerne den Verkäufer kennen

Seller avatar
Bewertungen des Ansehens basieren auf der Anzahl der Dokumente, die ein Verkäufer gegen eine Gebühr verkauft hat, und den Bewertungen, die er für diese Dokumente erhalten hat. Es gibt drei Stufen: Bronze, Silber und Gold. Je besser das Ansehen eines Verkäufers ist, desto mehr kannst du dich auf die Qualität der Arbeiten verlassen.
Grademasters West Virginia University
Folgen Sie müssen sich einloggen, um Studenten oder Kursen zu folgen.
Verkauft
115
Mitglied seit
3 Jahren
Anzahl der Follower
68
Dokumente
2599
Zuletzt verkauft
1 Jahren vor
Grademasters

3,8

46 rezensionen

5
20
4
9
3
11
2
2
1
4

Kürzlich von dir angesehen.

Warum sich Studierende für Stuvia entscheiden

on Mitstudent*innen erstellt, durch Bewertungen verifiziert

Geschrieben von Student*innen, die bestanden haben und bewertet von anderen, die diese Studiendokumente verwendet haben.

Nicht zufrieden? Wähle ein anderes Dokument

Kein Problem! Du kannst direkt ein anderes Dokument wählen, das besser zu dem passt, was du suchst.

Bezahle wie du möchtest, fange sofort an zu lernen

Kein Abonnement, keine Verpflichtungen. Bezahle wie gewohnt per Kreditkarte oder Sofort und lade dein PDF-Dokument sofort herunter.

Student with book image

“Gekauft, heruntergeladen und bestanden. So einfach kann es sein.”

Alisha Student

Häufig gestellte Fragen