I am currently learning python and I am trying to create a program that would allow a user to input their "change" and get a total. Personally I have been running it from the command line to test it as I go, but I'm having trouble getting it to respond the way I need it to.
Into the command line I put something like: filename.py 25 10 5 1
But the issue I'm having is that instead of accepting the numbers in the same line, I'm having to do something like:
filename.py
25
10
5
1
and then I'll get the total
What I want is:
filename.py 25 10 5 1
total
Here's the code I'm trying:
def coin_value(quarters, dimes, nickels, pennies):
firsttotal = .25 * quarters + .10 * dimes + .05 * nickels + .01 * pennies
total = round(firsttotal,2)
currency_string = "${:,.2f}".format(firsttotal)
print(f"The total value of your change is", currency_string)
coin_value(int(input()), int(input()), int(input()), int(input()))
Does anyone have any suggestions or know what I'm doing wrong?
sys.argvgives you basic access, but theargparsemodule (e.g. defining four positional arguments withtype=int) is better for writing customizable, maintainable command line parsing (and it generates your usage messages for you).