something wrong with my code, can some one help me? I need to do this task: a*(4*b-a)
a=(input('a='))
b=(input('b='))
print(4*a*b-a*a)
something wrong with my code, can some one help me? I need to do this task: a*(4*b-a)
a=(input('a='))
b=(input('b='))
print(4*a*b-a*a)
Hi @IghorPaniotov, welcome to the community!
I guess this is a logic error. Python follows PEMDAS, so update your print statement to:
Looks like a school task. So all i can say is to look carefully at what you are multiply in the print statement and what you actually should multiply.
There is an error there.
You are actually correct with the print statement.
a×(4b-a) = 4ab - a² by distributive law.
The error here is that you forgot to change datatype of the values.
Remember: input()
function always retuns values in str
datatype (string)
Take care of that to fix it
So there is another functionality of *
operator which is string replication.
You can use it when int * str
or str * int
For example:
2 * "hi"
hihi
4* "5"
5555
Before giving basically a full answer, please make sure this is not a school assignment and giving as much of an information as you did is basically cheating.
Alright, removed. Now there is just a clue