Skip to content

Latest commit

 

History

History
67 lines (62 loc) · 1.12 KB

28. Unit 3 - Lesson 3.md

File metadata and controls

67 lines (62 loc) · 1.12 KB

Default Arguments

Q1.

num1=int(input("num1: "))
num2=int(input("num2: "))
def simplecalc(a, b = 100):
	# write your code here
	print("addition:",a+b)
	print("subtraction:",a-b)
	print("multiplication:",a*b)
	

simplecalc(a = num1)
simplecalc(b = num2, a = num1)

Q2.

a=int(input("salary: "))
b=float(input("tax percentage: "))
def salary(a,b):
	print(a*(20/100))
	print((a*b)/100)
salary(a,b)

Q3. 1,3,4
Q4.

def fun(a="Padma",b=12):
	print(a,"is",b,"years old.")
fun("Aruna",16)
fun("Karuna",16)
fun(b=16)
fun("Karuna")
fun()

Variable-length Arguments

Q1. 1,2
Q2.

#Program to illustrate variable number of arguments
def mySum(*args):
	add=0
	for i in args:
		add=add+i
	return add
#Write your code here

print(mySum(1, 2, 3, 4, 5, 6, 7))	#7 arguments
print(mySum(1, 2))	#2 arguments
print(mySum(1, 2, 3))	#3 arguments

Q3.

#Program to illustrate Variable number of arguments
def largestNumber( * numbers):
	l1=[]
	for i in numbers:
		l1.append(i)
	print("largest:",max(l1))

# write your code here

largestNumber(1, 2, 3, 4)			#4 arguments
largestNumber(8, 9, 3, 4, 2, 5)		#6 arguments