![]() |
str_format_2var - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: str_format_2var (/thread-1048.html) |
str_format_2var - roadrage - Nov-29-2016 """ 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' """ 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)What am i doing wrong in this?? RE: str_format_2var - heiner55 - Nov-29-2016 print(args[0] % (args[1], args[2])) RE: str_format_2var - stranac - Nov-29-2016 There are a few other issues in addition to what heiner55 already wrote:
RE: str_format_2var - roadrage - Nov-29-2016 This works thank you... RE: str_format_2var - micseydel - Nov-29-2016 (Nov-29-2016, 05:28 PM)roadrage Wrote: This works thank you...It's an improvement, but as stranac pointed out it's not the solution. If I were your teacher, you'd get a 0 for what it seems you have here. If anything isn't clear, please make sure to ask us instead of ignoring it. |