Sumita Arora Solution

Explain with a code example the usage of default argument and keyword argument.

Default Argument def power(x,y=3):   for i in range(y):     r=r*x   return r a=intinput((“Enter Base”)) b=intinput((“Enter Exponent”)) total = power(a,b) print(total) Usage of Default Argument: •Matching arguments are not passed in the function call statement •Some argument always have same value. Keyword Argument def power(x,y):   for i in range(y):     r=r*x […]

Explain with a code example the usage of default argument and keyword argument. Read More »

What is utility of:
(i) default argument
(ii) keyword argument

Default Argument: It is a Parameter initialized with default value in function header or definition. It is useful when • Matching arguments are not passed in the function call statement • Some argument always have same value. Keyword Argument: Also known as named arguments. A value being passed during function call with specified name is

What is utility of:
(i) default argument
(ii) keyword argument
Read More »

What are arguments ? What are parameters ? How are these terms different yet related ? Give example.

Argument is data being passed to a function through function call.Parameter is data being received by a function in function header. Because both belongs to same function, Arguments appear in function call statement and Parameter appears in function header, so we can say these terms are related.

What are arguments ? What are parameters ? How are these terms different yet related ? Give example. Read More »

A program having multiple functions is considered better designed than a program without any functions. Why?

A program having functions is considered better designed because- 1) The program becomes easier to read 2) The program becomes less error prone 3) Complexity of program is reduced 4) Repetition of code is reduced 5)Making changes or updating is easier.

A program having multiple functions is considered better designed than a program without any functions. Why? Read More »

Create a dictionary named with three entries, for key ‘a’, ‘b’ and ‘c’.
What happened if you try to index a nonexistent key (D[‘d’]) ?
What does python do if you try to assign to a nonexistent key d.
e.g. D[‘d’]=‘spam’

if we try to index a nonexistent key (D[‘d’])  than it will produce ‘keyerror’. if we try to assign to a nonexistent key d than it will add a new element in dictionary.

Create a dictionary named with three entries, for key ‘a’, ‘b’ and ‘c’.
What happened if you try to index a nonexistent key (D[‘d’]) ?
What does python do if you try to assign to a nonexistent key d.
e.g. D[‘d’]=‘spam’
Read More »

error: Content is protected !!