These here forums are read-only. Click here to go to the new forums, where you can actually post and stuff!
Sorry for the inconvenience
-Andrew
Hello, so I recently started Python programming. I can't get past this bug. If any people here know how to fix it that would be great!
The Code:
amount = input("You're bill today:")
print("Your original amount:", amount) print("Your amount with a 15% and 20% tip:")
percent15 = amount * .15
percent20 = amount * .20
print(percent15) print(percent20)
The error:
You're bill today: 40 Your original amount: 40 Your amount with a 15% and 20% tip: Traceback (most recent call last): File "C:\Python33\general.py", line 10, in <module> percent15 = amount * .15 TypeError: can't multiply sequence by non-int of type 'float'
Whoa my # note got messed up.
The pound sign is markdown for BIG TEXT in these forums.
It looks like your input returns a String and you are trying to multiply the String by a float. Parse that input into an integer.
(Originally posted by gamerkd [Link])
pound sign
Nice try, Americans
££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££
(Originally posted by gamerkd [Link])
The ~~pound sign~~ octothorpe is markdown for BIG TEXT in these forums.
Happy? :p
amount = input("Enter your bill for today: ")
print("Your original amount: ", amount) print("Your amount with a 15% and 20% tip:")
percent15 = int(amount) * .15
percent20 = int(amount) * .20
print(repr(percent15)) print(repr(percent20))
(Originally posted by umby24 [Link])
amount = input("Enter your bill for today: ")
print("Your original amount: ", amount) print("Your amount with a 15% and 20% tip:")
percent15 = int(amount) * .15
percent20 = int(amount) * .20
print(repr(percent15)) print(repr(percent20))
Well you can't just show him how to fix the problem or he'll never learn.
In fact, this sounds a lot like a Homework assignment.
i don't even know python. I just used google.
(Originally posted by umby24 [Link])
i don't even know python. I just used google.
that's pretty much how I did LegendCraft
There are multiple things wrong with this. First:
print("string") print(bar)
is invalid syntax. It should be, for your usage:
print("string1 {0} {1}".format(foo, bar))
Anyways, the reason your code won't work is because the number you input is a string. The input() function ALWAYS returns a string. ex:
>>> amount = input("type a number: ")
50
>>> type(amount)
<class 'str'>
So, to make this program work, you want to use
amount = int(input("Your bill today: "))
which makes sure the input is an integer.
Final product:
amount = int(input("Your bill today: "))
percent15 = amount * 0.15
percent20 = amount * 0.20
print("Your original amount: {0}".format(amount))
print("Your amount with a 15% and 20% tip: {0} {1}".format(percent15, percent20))
Furthermore, if you don't understand this post fully, what you are experiencing is not a bug. It is because input() returns a string, and you cannot multiply, add, divide, etc. a string.