Question: ans # anything but q UserVals[] while (ans.lower() !'q'): UserVals.append(float (input('Enter a value: '))) ansinput ( 'Enter Q to quit or anything else to continue:
![ans # anything but q UserVals[] while (ans.lower() !'q'): UserVals.append(float (input('Enter](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66efb344386a3_02766efb343b0725.jpg)
ans # anything but q UserVals[] while (ans.lower() !'q'): UserVals.append(float (input('Enter a value: '))) ansinput ( 'Enter Q to quit or anything else to continue: ') Formatstr 'The values entered were: %5.2f' if ( len(UserVals) > 1): for val in UserVals [1:-1]: FormatStrFormatStr + ', FormatStrFormatStr'.' Formatstr Formatstr + ', %5.2f' else: # only one value entered print (Format str % tuple(UserVals)) Understand a few things about this code. We are filling a string a bit at a time to get the formatting correct. This lets us account for the user entering values that should be displayed differently (commas, the 'and' conjunction, etc.) depending on how many were entered The above code does not build the actual string that gets sent to the console. We could have also done that. The code above just builds the format string and then uses that for string interpolation with the list of user values, that we convert to a tuple for the interpolation. . . Write a Python program that asks the user for a series of numbers, as in the example above. But, there are some improvements to be made over the example. For each number, assume that if the number has no fractional part that it is to be displayed as an integer. If it has a non-zero fractional part, then display it using a floating point format that has 2 digits to the right of the decimal and is otherwise is no longer than needed to print the number (that is, with no extra leading spaces). Print the user's numbers on one line with commas and 'and's as above. Several example runs are shown below 1. C:\Users\brokow\UCM Classes\ME 02112019 Spring AssignmentsHW05-01 . py Enter a value: 3 Enter Q to quit or anything else to continue: q The values entered were: 3 ans # anything but q UserVals[] while (ans.lower() !'q'): UserVals.append(float (input('Enter a value: '))) ansinput ( 'Enter Q to quit or anything else to continue: ') Formatstr 'The values entered were: %5.2f' if ( len(UserVals) > 1): for val in UserVals [1:-1]: FormatStrFormatStr + ', FormatStrFormatStr'.' Formatstr Formatstr + ', %5.2f' else: # only one value entered print (Format str % tuple(UserVals)) Understand a few things about this code. We are filling a string a bit at a time to get the formatting correct. This lets us account for the user entering values that should be displayed differently (commas, the 'and' conjunction, etc.) depending on how many were entered The above code does not build the actual string that gets sent to the console. We could have also done that. The code above just builds the format string and then uses that for string interpolation with the list of user values, that we convert to a tuple for the interpolation. . . Write a Python program that asks the user for a series of numbers, as in the example above. But, there are some improvements to be made over the example. For each number, assume that if the number has no fractional part that it is to be displayed as an integer. If it has a non-zero fractional part, then display it using a floating point format that has 2 digits to the right of the decimal and is otherwise is no longer than needed to print the number (that is, with no extra leading spaces). Print the user's numbers on one line with commas and 'and's as above. Several example runs are shown below 1. C:\Users\brokow\UCM Classes\ME 02112019 Spring AssignmentsHW05-01 . py Enter a value: 3 Enter Q to quit or anything else to continue: q The values entered were: 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
