• 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 7 pages
Exam (elaborations)

Intro to Programming Logic Final Exam Questions with Complete Solutions

Document preview thumbnail
Preview 2 out of 7 pages

Intro to Programming Logic Final Exam Questions with Complete Solutions

Content preview

Intro to Programming Logic Final Exam
Questions with Complete Solutions

Write a statement that creates a list with the following strings: 'Einstein', 'Newton',
'Copernicus', and 'Kepler' . - ANSWER-names = ['Einstein', 'Newton', 'Copernicus',
'Kepler']

Assume names references a list. Write a for loop that displays each element of the
list. - ANSWER-for element in names:
print(element)

Assume the list of numbers1 has 100 elements, and numbers2 is an empty list. Write
code that copies the values in numbers1 to numbers2. - ANSWER-for item in
numbers1:
numbers2.append(item)

What will the following code print?

list1 = [40, 50, 60 ]
list2 = [ 10, 20, 30 ]
list3 = list1 + list2
print (list3) - ANSWER-[40, 50, 60, 10, 20, 30].

What does the following of the code display?

mystr = 'yes'
mystr += 'no'
mystr += 'yes'
print (mystr) - ANSWER-yesnoyes

What does the following code display?

mystr = 'abc' * 3
print (mystr) - ANSWER-abcabcabc

What will the following code display?

mystring = 'abcdefg'
print (mystring [2:5] ) - ANSWER-cde

What does the following code display?

numbers = [1, 2, 3, 4, 5, 6, 7 ]
print (numbers [4 : 6] ) - ANSWER-[5, 6]

What does the following code display?

, name = 'joe'

print (name . lower ( ) )
print (name. upper ( ) )
print (name) - ANSWER-joe
JOE
joe
joe

Assume choice references a string. The following if statement determines whether
choice is equal to 'Y' or 'y':

if choice == 'Y' or choice == 'y' :

Rewrite this statement so it only makes one comparison, and does not use the or
operator. (Hint: use either the upper or lower methods. ) - ANSWER-if choice.upper()
== 'Y'

Write a loop that counts the number of digits that appear in the string referenced by
mystring. - ANSWER-counter = 0
for ch in mystring:
if ch.isdigit():
counter +=1
print ('The number of digits is', counter)

Write a function that accepts a string as an argument and returns true if the
argument ends with the substring ' .com ' . Otherwise, the function should return
false. - ANSWER-def com_check(mystring):
if mystring.endswith('.com'):
return True
return False

Assume mystring references a string. Write a statement that uses a slicing
expression and displays the first 3 characters in the string. - ANSWER-
print(mystring[:3])

Look at the following statement:

mystring= ' cookies>milk>fudge>cake>ice cream '

Write a statement that splits this string, creating the following list:

[ 'cookies' , 'milk' , 'fudge' , 'cake' , 'ice cream' ] - ANSWER-mylist = mystring.split('>')

What will be the output after the following code is executed?

def pass_it(x, y):

z = x + ", " + y

Document information

Uploaded on
March 22, 2025
Number of pages
7
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$14.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.
lectknancy
3.8
(82)
Sold
342
Followers
27
Items
26160
Last sold
3 days 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