-1

Possible Duplicate:
Python 3.2.3 programming…Almost had it working

x = float(input("What is/was the cost of the meal?"))
y = float(input("What is/was the sales tax?"))
z = float(input("What percentage tip would you like to leave?"))

print ("Original Food Charge: ${}"
.format(x)))
print ("Sales Tax: ${}"
.format((y/100)*x)))
print ("Tip: ${}"
.format(x*(z/100)))
print ("Total Charge For Food: ${}"
.format(x+((y/100)*x)+((z/100)*x)))

output error:

line 10, in Syntax Error: .format(x))):line 1015

Someone report that this worked in their earlier version of python (v2.6 I think). I'm using the later 3.2.3 and racking my darn brain as to why this is not working to this version. It makes sense to me someone please ENLIGHTEN me.

4

3 に答える 3

4

You missed an end bracket after the third print: .format(x*(z/100)))

Here is what appears to be a working version after I fixed the brackets:

x = float(input("What is/was the cost of the meal?"))
y = float(input("What is/was the sales tax?"))
z = float(input("What percentage tip would you like to leave?"))

print("Original Food Charge: ${}".format(x))
print("Sales Tax: ${}".format((y/100)*x))
print("Tip: ${}".format(x*(z/100)))
print("Total Charge For Food: ${}".format(x+((y/100)*x)+((z/100)*x)))

Also there is no need for newlines if the line width is less than 79.

于 2012-09-24T04:33:17.557 に答える
2

You're missing a close paren on the preceding line:

.format(x*(z/100))
于 2012-09-24T04:33:30.620 に答える
2

There is a parentheses missing after .format(x*(z/100)) that belongs to the preceding print.

It should be:

print ("Tip: ${}".format(x*(z/100)))

UPDATE: Not sure if you got it working or not yet, here is the complete code after fixing your unbalanced parentheses...

x = float(input("What is/was the cost of the meal?"))
y = float(input("What is/was the sales tax?"))
z = float(input("What percentage tip would you like to leave?"))

print ("Original Food Charge: ${}"
.format(x))
print ("Sales Tax: ${}"
.format((y/100)*x))
print ("Tip: ${}"
.format(x*(z/100)))
print ("Total Charge For Food: ${}"
.format(x+((y/100)*x)+((z/100)*x)))
于 2012-09-24T04:34:11.307 に答える