Computer Science
Write a Python program using two functions area and perimeter to compute the area and perimeter of a rectangle. The program should take length and breadth of the rectangle as input from the user.
Python
Python Functions
29 Likes
Answer
def area(a, b):
return (a * b)
def perimeter(a, b):
return (2 * (a + b))
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
print ("Area = ", area(l, b))
print ("Perimeter = ", perimeter(l, b))Output
Enter length: 9
Enter breadth: 4
Area = 36.0
Perimeter = 26.0
Answered By
16 Likes
Related Questions
The code provided below is intended to swap the first and last elements of a given tuple. However, there are syntax and logical errors in the code. Rewrite it after removing all errors. Underline all the corrections made.
def swap_first_last(tup) if len(tup) < 2: return tup new_tup = (tup[-1],) + tup[1:-1] + (tup[0]) return new_tup result = swap_first_last((1, 2, 3, 4)) print("Swapped tuple: " result)Assertion (A): Positional arguments in Python functions must be passed in the exact order in which they are defined in the function signature.
Reasoning (R): This is because Python functions automatically assign default values to positional arguments.
- Both A and R are true, and R is the correct explanation of A.
- Both A and R are true, and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.