Computer Science, asked by khushi801550, 5 months ago

write python expression for mathematical expression (a+b)^2=a^2+b^2+2ab​

Answers

Answered by devip649
3

Explanation:

Operators are the symbols which tells the Python interpreter to do some mathematical or logical operation. Few basic examples of mathematical operators are given below:

>>> 2 + 3

5

>>> 23 - 3

20

>>> 22.0 / 12

1.8333333333333333

To get floating result you need to the division using any of operand as floating number. To do modulo operation use % operator

>>> 14 % 3

2

Example of integer arithmetic

The code

#!/usr/bin/env python3

days = int(input("Enter days: "))

months = days / 30

days = days % 30

print("Months = %d Days = %d" % (months, days))

The output

$ ./integer.py

Enter days: 265

Months = 8 Days = 25

In the first line I am taking the input of days, then getting the months and days and at last printing them. You can do it in a easy way

#!/usr/bin/env python3

days = int(input("Enter days: "))

print("Months = %d Days = %d" % (divmod(days, 30)))

The divmod(num1, num2) function returns two values , first is the division of num1 and num2 and in second the modulo of num1 and num2.

Similar questions