Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 18 pages
Exam (elaborations)

Python Coding TEST Questions And Answers Verified 100% Correct

Document preview thumbnail
Preview 3 out of 18 pages

Python Coding TEST Questions And Answers Verified 100% Correct 1 - ANSWER (Chapter 3) 'In the following code (numbers added) - which will be the last line to execute successfully? (1) astr = 'Hello Bob' (2) istr = int(astr) (3) print 'First', istr (4) astr = '123' (5) istr = int(astr) (6) print 'Second', istr -1 - ANSWER (Chapter 3) For the following code: astr = 'Hello Bob' istr = 0 try: istr = int(astr) except: istr = -1 What will the value for istr after this code executes? A built-in function - ANSWER (Chapter 4) In Python what is the raw_input() feature best described as? def - ANSWER (Chapter 4) Which Python keyword indicates the start of a function definition? 10 20 - ANSWER (Chapter 4) What will the following Python code print out? def func(x) : print x func(10) func(20) print greet('fr'),'Michael' Avoiding writing the same non-trivial code more than once in your program - ANSWER (Chapter 4) What is the most important benefit of writing your own functions? x - ANSWER (Chapter 4) In the following Python code, which of the following is an "argument" to a function? x = 'banana' y = max(x) print y print x There - ANSWER (Chapter 4) What does the following code print out? def thing(): print 'Hello' print 'There' You de-indent a line of code to the same indent level as the def keyword - ANSWER (Chapter 4) In Python, how do you indicate the end of the block of code that makes up the function? print 'World' - ANSWER (Chapter 4) Which line of the following Python program is useless? def stuff(): print 'Hello' return print 'World' Bonjour Michael - ANSWER (Chapter 4) What will the following Python program print out? def greet(lang): if lang == 'es': return 'Hola' elif lang == ' fr': return 'Bonj our' else: return 'Hello' stuff() 2 - ANSWER (Chapter 4)What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug - so read carefully). def addtwo(a, b): added = a + b return a x = addtwo(2, 7) print x Hellothere - ANSWER (Chapter 6) What does the following Python Program print out? str1 = "Hello" str2 = 'there' bob = str1 + str2 print bob 42 - ANSWER (Chapter 6) What does the following Python program print out? x = '40' y = int(x) + 2 print y printx[8] - ANSWER (Chapter 6) How would you use the index operator [] to print out the letter q from the following string? x = 'From ' print x[14:17] - ANSWER (Chapter 6) How would you use string slicing [:] to print out 'uct' from the following string? x = 'From ' letter - ANSWER (Chapter 6) What is the iteration variable in the following Python code? for letter in 'banana' : print letter 42 - ANSWER (Chapter 6) What does the following Python code print out?

Content preview

Python Coding TEST Questions And Answers Verified
100% Correct
1 - ANSWER (Chapter 3) 'In the following code (numbers added) - which will be the last
line to execute successfully?

(1) astr = 'Hello Bob'
(2) istr = int(astr)
(3) print 'First', istr
(4) astr = '123'
(5) istr = int(astr)
(6) print 'Second', istr

-1 - ANSWER (Chapter 3) For the following code:

astr = 'Hello Bob'
istr = 0 try: istr
= int(astr)
except: istr = -1
What will the value for istr after this code executes?

A built-in function - ANSWER (Chapter 4) In Python what is the raw_input() feature best
described as?

def - ANSWER (Chapter 4) Which Python keyword indicates the start of a function
definition?

10
20 - ANSWER (Chapter 4) What will the following Python code print out?

def func(x) :

print x

func(10)

func(20)

,Bonjour Michael - ANSWER (Chapter 4) What will the following Python
program print out?
def greet(lang):
if lang == 'es':
return 'Hola'
elif lang == 'fr':
return 'Bonjour'
else:
return 'Hello'

print greet('fr'),'Michael'

Avoiding writing the same non-trivial code more than once in your program - ANSWER
(Chapter 4) What is the most important benefit of writing your own functions?

x - ANSWER (Chapter 4) In the following Python code, which of the following is an
"argument" to a function?

x = 'banana'

y = max(x)

print y

print x

There - ANSWER (Chapter 4)
What does the following code print out?

def thing():

print 'Hello'

print 'There'

You de-indent a line of code to the same indent level as the def keyword - ANSWER
(Chapter 4) In Python, how do you indicate the end of the block of code that makes up
the function?

print 'World' - ANSWER (Chapter 4)
Which line of the following Python program is useless?
def stuff(): print 'Hello' return
print 'World'

, stuff()

2 - ANSWER (Chapter 4)What does the following Python code print out? (Note that this
is a bit of a trick question and the code has what many would consider to be a flaw/bug -
so read carefully). def addtwo(a, b): added = a + b
return a

x = addtwo(2, 7)
print x

Hellothere - ANSWER (Chapter 6)
What does the following Python Program print out?
str1 = "Hello"

str2 = 'there'

bob = str1 + str2

print bob

42 - ANSWER (Chapter 6) What does the following Python program print out?
x = '40'

y = int(x) + 2

print y

printx[8] - ANSWER (Chapter 6)
How would you use the index operator [] to print out the letter q from the following
string?
x = 'From '

print x[14:17] - ANSWER (Chapter 6) How would you use string slicing [:] to print out
'uct' from the following string? x = 'From '

letter - ANSWER (Chapter 6)
What is the iteration variable in the following Python code? for
letter in 'banana' :

print letter

42 - ANSWER (Chapter 6)
What does the following Python code print out?

Document information

Uploaded on
September 14, 2025
Number of pages
18
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$13.49

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.
TopGradeGuru
1.5
(2)
Sold
16
Followers
0
Items
2365
Last sold
1 month 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