CPT168 Ch10

Ace your homework & exams now with Quizwiz!

The join() method of a list can be used to combine

the items in the list into a string that's separated by delimiters

The isdigit() method of a string returns

true if the string contains only digits

What is the value of s3 after the code that follows is executed?s1 = "abc def ghi";s2 = s1[1:5]s3 = s2.replace('b', 'z')print(s3)

zc d

What is the value of the variable named result after this code is executed? email = "marytechknowsolve.com" result = email.find("@")

-1

What is the value of s2 after the code that follows is executed?s1 = "118-45-9271"s2 = ""for i in s1:if i != '-': s2 += is1.replace("-", ".")

118459271

A Unicode character is represented by a

2-digit code

What is the value of the variable named result after this code is executed?email = "joel.murach@com"result = email.find("@") - email.find(".")print(result)

7

What will be displayed after the following code executes?book_name = "a tale for the knight"book = book_name.title()print(book)

A Tale For The Knight

Given the following code, what will be displayed after the code executes?name = "Mervin the Magician"words = name.split()print(words[0] + ", you are quite a " + words[2].lower())

Mervin, you are quite a magician

1. phone_number = input("Enter phone number: ").strip()2. if len(phone_number) == 10:3. phone_number = "(" + phone_number[:3] + ")" + phone_number[3:6] + "-" + phone_number[6:]4. print("Phone number: ", phone_number)5. else:6. print("Phone number: ", "Phone number must be 10 digits") Refer to Code Example 10-1. If the user enters 5551234567 at the prompt, what will be displayed?

Phone number: (555)123-4567

phone_number = input("Enter phone number: ").strip()2. if len(phone_number) == 10:3. phone_number = "(" + phone_number[:3] + ")" + phone_number[3:6] + "-" + phone_number[6:]4. print("Phone number: ", phone_number)5. else:6. print("Phone number: ", "Phone number must be 10 digits") Refer to Code Example 10-1. If the user enters two extra spaces at the end of a phone number, what will happen?

The length of the number will be greater than 10 so the else clause will execute

phone_number = input("Enter phone number: ").strip()2. if len(phone_number) == 10:3. phone_number = "(" + phone_number[:3] + ")" + phone_number[3:6] + "-" + phone_number[6:]4. print("Phone number: ", phone_number)5. else:6. print("Phone number: ", "Phone number must be 10 digits") Refer to Code Example 10-1. If the user enters two extra spaces at the end of a phone number, what will happen?

The strip() method on line 1 will strip away the extra whitespace.

Which of the following statements will modify the string that's stored in a variable named s?

You can't modify a string.

To retrieve the fourth character in a string that's stored in a variable named city, you can use this code:

city[3]

Which of the following code snippets will result in this display:Countdown...5...4...3...2...1...Blastoff!

counting = "54321"print("Countdown...")for char in counting:print(char + "...")print("Blastoff!")

To access the first three chracters in a string that's stored in a variable named message, you can use this code:

first_three = message[0:3]

To determine the length of a string that's in a variable named city, you can use this code.

len(city)

Which of the Python examples tthat follow can not be used to create a string named n2?

numbers = [8, 17, 54, 22, 35] n2 = "".join(numbers)

Which of the following will display this result? B=66

print("B = ", ord("B"))

If word = "a horse", which of the following snippets of Python code will display this result?a horse! a horse! My kingdom for a horse!

print((word+"!") * 2 + "My kingdom for" +word + "!")

Given the following code, what would display? car = "PORSCHE" color = "red" my_car = car.join(color) print(my_car)

rPORSCHEePORSCHEdPORSCHE


Related study sets

Agile mock test - Stakeholder Engagement 2

View Set

141 - Inflammation - EAQ - Iggy (Med-Surg) - Ch 17

View Set

Introduction to the nervous system

View Set

26401 Load Calculations - Feeders and Services

View Set

AIS Chapter 9: Database Management Systems

View Set

Macroeconomics Midterm 2 Chapter 15

View Set