w3resource

Python: Print "30+20=50"

Python Basic: Exercise-88 with Solution

Sum Expression Printer

Given variables x=30 and y=20, write a Python program to print "30+20=50".

Pictorial Presentation:

Print '30+20=50'

Sample Solution-1:

Python Code:

# Define two variables, x and y, and assign values 30 and 20, respectively.
x = 30
y = 20
# Print the sum of x and y using string formatting.
print("\n%d+%d=%d" % (x, y, x+y))

Sample Output:

30+20=50

Sample Solution-2:

Python Code:

# Define two variables, x and y, and assign values 30 and 20, respectively.
x = 30
y = 20
# Print the sum of x and y using the format method to insert the variables.
print("{0}+{1}={2}".format(x, y, x + y))

Sample Output:

30+20=50

Sample Solution-3:

Python Code:

# Define two variables, x and y, and assign values 30 and 20, respectively.
x = 30
y = 20
# Print the sum of x and y using the format method to insert the variables.
print("{}+{}={}".format(x, y, x + y))

Sample Output:

30+20=50

Python Code Editor:

 

Previous: Write a Python program to get the size of a file.
Next: Write a Python program to perform an action if a condition is true.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/python-basic-exercise-88.php