# Complex Statements

#### Resources

Finally, let’s look at how we can rewrite some of our previous Python programs by combining expressions into more complex statements. Python allows us to perform multiple actions on a single line of code, provided they can all be combined in some way to create a single statement.

Let’s consider the example on the previous page, shown here:

``````text_one = input("Enter the first number: ")
one = int(text_one)
text_two = input("Enter the second number: ")
two = int(text_two)
one = one * one
two = two * two
total = one + two
print(f"The sum of squares of {one} and {two} is {total}")``````

There are many ways we can write this program to perform the same work. For example, the process of computing the sum of squares itself can actually be reduced to a single line of code as seen below:

``total = (one * one) + (two * two)``

We can perform multiple mathematical operations in a single expression, and as long as we either use parentheses or pay attention to the order of operations, we’ll get the expected answer. We don’t have to store the intermediate values in variables, since Python will do that for us when it evaluates the expression.

Likewise, we can put the `input()` function inside of the `int()` function, allowing us to read input as a string and convert it to an integer in a single line:

``````one = int(input("Enter the first number: "))
two = int(input("Enter the second number: "))
total = (one * one) + (two * two)
print(f"The sum of squares of {one} and {two} is {total}")``````

Finally, we can also move the computation of the sum of squares directly into the f-string. When Python tries to print the f-string, the interpolation process must compute that value before it can print the output.

``````one = int(input("Enter the first number: "))
two = int(input("Enter the second number: "))
print(f"The sum of squares of {one} and {two} is {(one * one) + (two * two)}")``````

Functionally, this code will create the exact same output as the previous code, but it will do so using fewer variables and statements. Each statement is simply more complex, consisting of multiple expressions.