Nov-29-2016, 03:42 PM
"""
Create a function called str_format_2var, taking three arguments:
- A string, containing two formatting markers supported by Python,
like
- Value to be substituted for the first formatting marker
- Value to be substituted for the second formatting marker
The function must:
1. Return a single string, containing where the formatting markers are
replaced with the second and third function arguments
2. When inspected, would return the following help string:
Replace two formatting markers with the variables that were passed in
For example:
str_format_2var('%d %s bottles', 10, 'green') -> '10 green bottles'
str_format_2var('%s is %.2f', 'Pi', 3.14) -> 'Pi is 3.14'
"""
What am i doing wrong in this??
Create a function called str_format_2var, taking three arguments:
- A string, containing two formatting markers supported by Python,
like
%s
, %d
, etc.- Value to be substituted for the first formatting marker
- Value to be substituted for the second formatting marker
The function must:
1. Return a single string, containing where the formatting markers are
replaced with the second and third function arguments
2. When inspected, would return the following help string:
Replace two formatting markers with the variables that were passed in
For example:
str_format_2var('%d %s bottles', 10, 'green') -> '10 green bottles'
str_format_2var('%s is %.2f', 'Pi', 3.14) -> 'Pi is 3.14'
"""
1 2 3 4 5 6 7 8 |
def str_format_2var( * args): print (args[ 0 ], % { "d" : args[ 1 ], 's' : args[ 2 ]}) x = '%d %s bottles' y = 10 z = 'green' str_format_2var(x,y,z) |