Myles Clough
Myles Clough

Reputation: 21

I am trying to create a simple program to calculate percentage change, but I am having issues with printing the answer

I am just starting out on python and i have very little previous experience with coding.

I have created a simple program to calculate percentage change, but with the line to print I am trying something slightly more complicated.

My current code is below:

num1 = float(input("what is the original number?"))

modi = float(input("How much do you want to increase it by?(please use 0.83/1.56 types rather than percentages)"))

ans = num1 * modi

print(ans,"is",modi,"times"if modi > 1 ("greater than")else "less than",num1)

The calculation works fine, but whenever i integrate the more advanced version of the print line it comes up with the error:

TypeError: 'int' object is not callable

I don't see anything wrong, can you?

Upvotes: 2

Views: 63

Answers (1)

DYZ
DYZ

Reputation: 57033

You incorrectly use the if expression. Should be "greater than" if modi > 1 else "less than". In general, the syntax of the expression is: true_value if condition else false_value. As written in your code snippet, Python interprets 1 ("greater than") as an attempt to call function 1() with the parameter "greater than", thus the complaint about 1 being not callable.

Upvotes: 1

Related Questions