Ch. 3

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Write an expression whose value is the concatenation of the three str values associated with name1 , name2 , and name3 , separated by commas. So if name1 , name2 , and name3 , were (respectively) "Neville", "Dean", and "Seamus", your expression's value would be "Neville,Dean,Seamus".

name1 + "," + name2 + "," + name3

Initialize the variable oneSpace , to a string consisting of a single space.

oneSpace = ' '

Write an expression that concatenates the String variable suffix onto the end of the String variable prefix .

prefix + suffix

Write an expression whose value is the same as the str associated with s but with all lower caseletters. Thus, if the str associated with s were "McGraw15" , the value of the expression would be "mcgraw15" .

s.lower()

Given a variable s associated with a str , write an expression whose value is a str that is identical except that all the letters in it are upper-case. Thus, if the str associated with s were "McGraw15" , the value of the expression would be "MCGRAW15" .

s.upper()

Write an expression that is the concatenation of the str associated with s1 and that associated with the str s2 .

s1 + s2

Associate the variable named text with the empty string.

text = ''

Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word . So, if word contains "sadly", the value of the expression would be the string "(sadly)"

"(" + word + ")"

Given a String variable address , write a String expression consisting of the string "http://" concatenated with the variable 's String value. So, if the variable refers to "www.turingscraft.com", the value of the expression would be "http://www.turingscraft.com".

"http://" + address

Write a String constant consisting of exactly 5 exclamation marks.

'!!!!!'

Write a String constant that is the empty string.

''

Write an expression that is the concatenation of the strings "Hello" and "World" .

'Hello' + 'World'

Associate two String variables named background and selectionColor with the values "white" and "blue" respectively.

background = "white" selectionColor = "blue"

Initialize the variable empty to the empty string.

empty = ''

Associate the variable foreground with the value "red" .

foreground = 'red'

Write code to assign to the variable format a formatting string that will display three values referenced by the variables quantity (type int ), description (type str ), and unitPrice (type float ) in the format illustrated by: (type "_10 One-inch Three-ring binder_____________ $___5.50" ). The quantity is displayed right-justified in 3 print positions, the description is displayed left-justified in 30 print positions, and the amount is displayed after a dollar sign with a total of 7 print positions and two digits after the decimal point. In the example, an underscore character is used to indicate the presence of a filler space. The underscores are not part of the actual string.

format = "%3d %-30s $%7.2f"


Kaugnay na mga set ng pag-aaral

Chapter 3 Financial Accounting Quiz

View Set

AP U.S. Government & Politics: Chapter 6

View Set

PrepU Chapter 36: Management of Patients with Musculoskeletal Disorders

View Set

chapter 17 Prep U- Implementation

View Set

NURS 212 (Final and last chapter)

View Set