Unit 3 - Lesson 5

28.1.1. Fruitful functions - an overview

(a) A fruitful function is a function, it returns a value when it is called.
(b) A return statement consists of the return keyword followed by an expression.
(c) Python returns immediately when it reaches a return statement .

28.1.2. A simple fruitful function

def largestinthree(a, b, c):
	if a>b and a>c:
		return a
	elif b>c:
		return b
	else:
		return c
	# write your code here to find the largest number in a, b and c
		
num1 = int(input("Please enter a value for num1: "))
num2 = int(input("Please enter a value for num2: "))
num3 = int(input("Please enter a value for num3: "))

result = largestinthree(num1, num2, num3)

print("Largest of the values entered is", result)

28.1.3. Write a program to find gcd of two given numbers.

def computeGCD(x, y):
	while y:
		x,y=y,x%y
	return x
#write your code here..


a = int(input("x: "))
b = int(input("y: "))
print (computeGCD(a, b))

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.