Skip to content

Latest commit

 

History

History
98 lines (91 loc) · 1.53 KB

26. Unit 3 - Lesson 1.md

File metadata and controls

98 lines (91 loc) · 1.53 KB

Basics of Functions

Q1. 1,2
Q2. 1,2
Q3.

def helloworld():
	print("Hello World")
	print("Good morning")
	print("Have a nice day")
	print("The function ends")
	# write your code here
	
	
helloworld()

Q4.

def add(x, y):
	return a+b
	# add x, y and print the result
	
def sub(x, y):
	# subtract x, y and print the result
	return a-b
def mul(x, y):
	# multiply x, y and print the result
	return a*b
a=int(input("x: "))
b=int(input("y: "))
print(add(a,b))
print(sub(a,b))
print(mul(a,b))
# take inputs x and y from the user
# call the functions add,sub, mul 

Q5.

# write your code here
def add(x,y):
	return a+b
def sub(x,y):
	return (a-b)
def mul(a,y):
	return a*b
a=int(input("a: "))
b=int(input("b: "))
print(add(a,b))
print(sub(a,b))
print(mul(a,b))

Q6. 1,2,4
Q7.

def abc():
	"""Function is defined to print string abc."""
	print("abc")

def pqr(a, b):
	"""Function is defined to print the product of parameters passed.
	
	a -- is the first parameter.
	b -- is the second parameter.
	"""
	print(a * b)
print(abc.__doc__)
print(pqr.__doc__)

# Write your code here to print docstring's of abc and pqr methods

Q8.

def addavg(x,y):
	return (a+b,(a+b)/2)
def sub(x,y):
	return (a-b)
def mul(x,y):
	return(a*b)
a=int(input("a: "))
b=int(input("b: "))
print("sum, average:",addavg(a,b))
print("subtraction:",sub(a,b))
print("multiplication:",mul(a,b))

Q9.

def add(x,y):
	return a+b
def sub(x,y):
	return a-b
a=int(input("a: "))
b=int(input("b: "))
print("addition:",add(a,b))
print("subtraction:",sub(a,b))