Question: Functions can be used to replace multiple code statements that perform essentially the same task with different values. This occurs in the Tic - Tac

Functions can be used to replace multiple code statements that perform essentially the same task with different values. This occurs in the Tic-Tac-Toe game program within the tutorial. See the printBoard function created there as an example. Functions often need to switch between doing something based on their input, such as offering different queries to a user. What string method could be used to switch between printing "select a column" and "select a row"?
a.)
The .swapcase() method; for example,
col_or_row = 'column'
print("The {} must be between 1 and 3.".swapcase(col_or_row))
b.)
The .title() method; for example,
col_or_row = 'column'
print("The {} must be between 1 and 3.".title(col_or_row))
c.)
The .index() method; for example,
col_or_row = 'column'
print("The {} must be between 1 and 3.".index(col_or_row))
d.)
The .format() method; for example,
col_or_row = 'column'
print("The {} must be between 1 and 3.".format(col_or_row))

Step by Step Solution

3.41 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The best string method to use in this scenario is d format method Heres why the other options are no... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!