0

Hey guys! Can you describe me what’s the difference between these two codes. Coz both of them give the same result

def average(n1,n2): m = (n1 + n2)/2 return m a = int(input("A= ")) b = int(input("B= ")) avrg = average(a,b) print(round(avrg,2)) #what’s a ROUND? I DON’t KNOW def average(n1,n2): m = (n1 + n2)/2 return m a = int(input("A= ")) b = int(input("B= ")) average(a,b)

1st May 2021, 2:35 AM
Wangzi
4 Antworten
+ 2
Hey Wangzi Python's round() function requires two arguments. First is the number to be rounded. Second argument decides the number of decimal places to which it is rounded.Here, the second parameter is optional. To round the number to 2 decimals, give second argument as 2. If third digit after decimal point is greater than 5, last digit is increased by 1. >>> round(1.4756,2) 1.48 >>> round(1.3333,2) 1.33
1st May 2021, 2:53 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
+ 3
Python provides an inbuilt function round() which rounds off to the given number of digits and returns the floating point number, if no number of digits is provided for round off , it rounds off the number to the nearest integer. SYNTAX:- round(number, number of digits) Where, 1) number - number to be rounded 2) number of digits (Optional) - number of digits up to which the given number is to be rounded. EXAMPLE:- # for integers print(round(15)) # for floating point print(round(51.6)) print(round(51.5))  print(round(51.4)) OUTPUT:- 15 52 52 51 Note:- When .5 is there round will return the nearest even integer. May this will help you
1st May 2021, 3:02 AM
Aman Jain
Aman Jain - avatar
0
thank you very much!)
2nd May 2021, 9:01 AM
Wangzi
0
hey Mate! Got it thank you!)
2nd May 2021, 9:01 AM
Wangzi