﻿ Python: Print "30+20=50" - w3resource

Python: Print "30+20=50"

Python Basic: Exercise-88 with Solution

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

Pictorial Presentation:

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:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿