Question: Consider the following simple program and note how repetitive it is to prompt for the inputs. ` ` ` def main ( ) : price

Consider the following simple program and note how repetitive it is to prompt for the inputs.
```
def main() :
price1= float(input("First item: "))
print()
price2= float(input("Next item: "))
print()
rate = float(input("Tax rate in percent: "))
total = price1+ price2
tax = total * rate /100
print("Amount due:", total + tax)
```
Rearrange these lines of code into an alternate solution with a reusable helper function. Put the helper function after main and be sure to call the main function after the helper function definition. Empty print statements are included for output formatting.
How to use this tool
Unused
```
tax = total * rate /100
rate = readFloat("Tax rate in percent")
print()
price1= readFloat("First item")
print()
```
return value
price2= readFloat("Second item")
print()
value = float(input(prompt +": "))
total = price1+ price2
print("Amount due:", total + tax)
def readFloat(prompt) :
Consider the following simple program and note

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!