I need help with the following:

#Get information from user
print("I'll help you determine how long you will need to save.")
name = input("What's your name? ")
item = input("What is your savings for? ")
balance = float (input("OK, ", name, ". Please enter the cost of          the ", item, ": "))
If (balance<0):
print("Looks like you already have saved enough!")
balance = 0
payment = 1
else:
payment = float(input("Enter how much you will save each  period:"))
if (payment <=0):
    payment = float(input("Savings must be positive. Please enter a positive value:"))
#Calculate number of payments that will be needed
num_remaining_payments = balance/payment
#Present information to user
print (name, ", you must make", num_remaining_payments, "more payments, and then you'll have your ", item, ":")

(When I run I get the following error)

I'll help you determine how long you will need to save.
What's your name? john
What is your savings for? car
Traceback (most recent call last):
  File         "/Users/terrythompson/Library/Preferences/PyCharmCE2019.1/     scratches/my first program.py", line 5, in <module>
balance = float (input("OK, ", name, ". Please enter the cost of     the ", item, ": "))

TypeError: input expected at most 1 arguments, got 5

Please advise.

Thank you

Recommended Answers

All 4 Replies

It's been quite a while since I used a version of BASIC that old but I suspect

balance = float (input("OK, ", name, ". Please enter the cost of     the ", item, ": "))

is complaining because of the number of parameters you give for input. Try concatenating all of the values and passing them to input as one string.

Sorry. I'm a very beginner.. I'm taking a video class and the instructor did not say anything was wrong with code. he says it works. How do I concatenate all of the values and passing them to input as one string?

Thanks

Without looking up the exact syntax, you might try something like

prompt = "OK, " &  name &  ". Please enter the cost of     the " &  item & ": "
balance = float(input(prompt))

The concatenation operator may be a + instead of &.

ok thanks I'll give it a try and report it later.

Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.