Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this Python programming/coding problem! Im using Python 3.7.2 PythonWin or another app on my MacBook that is also 3.7.2. If you

Please help me with this Python programming/coding problem! Im using Python 3.7.2 PythonWin or another app on my MacBook that is also 3.7.2.
If you could use # throughout your code to explain what youre doing that would be great!
Please do not make the code super complex! This is an entry level course and Id just like to see how it is done so I can learn for future quizzes and tests!
image text in transcribed
Thanks!
The we have seen the print statement send output to the console using a string with format specifiers (the % tokens in the string). We often put that string in our code as a literal. But, we can also build the string up, so that the format specifiers in it are custom to the values they will print out. The following code allows the user to enter any number of values and then prints them all out on one formatted line. ans ,'y' # anything but q while (ans . lower() 4'): UserVals.append (float (input ( Enter a value:))) ans input ( Enter Q to quit or anything else to continue:') Jost Ar re fere nce Formatstr = 'The values entered were : %5.2f. if ( len(UserVals) >1): for val in UserVals[1:-1]: FormatStr + ., %5.2f. Formatstr + ", and %5.2f. Formatstr FormatStr else: # only one value entered FormatStr FormatStr' print(FormatStr % 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. 1.) 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 usin 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 eral example runs are shown below C: Users\brokow \UCM Classes VME 82112019 Spring Assignments>Hwes 01.py Enter a value: 3 shat Enter Q to quit or anything else to continue: q The values entered were: 3 output Should

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

How would you measure your carbon footprint?

Answered: 1 week ago

Question

1. Describe the factors that lead to productive conflict

Answered: 1 week ago