231k views
1 vote
c=a+b gives you an integer answer if both a and b are integers. Whereas it combines the values of a and b if a and b are of string type. Justify the statement with sample code.

User VanagaS
by
4.1k points

2 Answers

3 votes

Final answer:

In mathematics, the addition operation is commutative, meaning the order of numbers does not affect the result. This property applies to both ordinary numbers and adding strings in programming languages.

Step-by-step explanation:

In mathematics, the addition operation is commutative, which means that the order of the numbers being added does not affect the result. For example, 2 + 3 is the same as 3 + 2. This property holds for ordinary numbers as well as for adding strings in programming languages.



Here is a sample code in Python to illustrate the concept:



a = 2
b = 3

# Integer addition
c = a + b
print(c) # Output: 5

a = '2'
b = '3'

# String concatenation
c = a + b
print(c) # Output: 23

User Ssdesign
by
4.5k points
6 votes

Answer:

Step-by-step explanation:
a=input("a=")

b=input("b=")

c=a+b

print(c)

this works^

User Eisa Adil
by
4.3k points