+ 1

Can Anyone tell me how to solve this? Project Name: Square up

Tuples can be used to output multiple values from a function. You need to make a function called calc(), that will take the side length of a square as its argument and return the perimeter and area using a tuple. The perimeter is the sum of all sides, while the area is the square of the side length. Sample Input: 3 Sample Output: Perimeter: 12 Area: 9

19th May 2021, 6:48 AM
Tanjiro
8 Respuestas
+ 5
Try this def calc(x): p=4*x a=x*x return (p,a) side = int(input()) p, a = calc(side) print("Perimeter: " + str(p)) print("Area: " + str(a))
20th Jun 2021, 1:54 PM
Zahed Shaikh
Zahed Shaikh - avatar
+ 4
Ok those answers might be technically correct, however the excercise was to achieve this through unpacking tuples, therefore here is the correct solution imo. def calc(x): #your code goes here return (x*4, x*x) side = int(input()) p, a = calc(side) print("Perimeter: " + str(p)) print("Area: " + str(a))
5th Oct 2021, 12:24 PM
Curious George
Curious George - avatar
+ 2
def calc(x): #your code goes here return((4*x, x*x)) side = int(input()) p, a = calc(side) print("Perimeter: " + str(p)) print("Area: " + str(a))
11th Dec 2021, 8:38 AM
Shabari Nathan
Shabari Nathan - avatar
+ 1
# you can solve it with any of these ways: def calc(x): sideLength = x print(f"area = {sideLength ** 2}") print(f"perimeter = {sideLength * 4}") calc(int(input())) calcs = lambda x : (x**2, x*4) c1, c2 = calcs(int(input())) print(f'area = {c1}', f'\nperimeter = {c2}') def calc2(x): return (x**2, x*4) a, b = calcs(int(input())) print(str(a) + ' is area', str(b) + ' is perimeter')
23rd Nov 2021, 10:44 PM
Mohammad Jamal Mahmoud Al Jadallah
Mohammad Jamal Mahmoud Al Jadallah - avatar
0
Just use the stmt, return (peri, area) While catching, use 2 variables like res1, res2 = calc(4) print("Perimeter :", res1) print("Area:", res2) Hope you know how to declare a function and the logic behind solving this prblm.
19th May 2021, 6:54 AM
sarada lakshmi
sarada lakshmi - avatar
0
def calc(x): #your code goes here return side*4 , side**2 side = int(input()) p, a = calc(side) print("Perimeter: " + str(p)) print("Area: " + str(a))
30th Jan 2022, 7:54 PM
Ruben Vivas G
Ruben Vivas G - avatar
0
def calc(x): p=4*x a=x*x return (p,a) side = int(input()) p, a = calc(side) print("Perimeter: " + str(p)) print("Area: " + str(a)) done...!
7th Mar 2022, 3:17 PM
Nikhila
0
def calc(x): #your code goes here p = side+side+side+side a = side**2 return p, a side = int(input()) p, a = calc(side) print("Perimeter: " + str(p)) print("Area: " + str(a))
17th May 2022, 3:39 PM
Junior Jackson
Junior Jackson - avatar