Functions and Recursions Theory

Descrição

Coding FlashCards sobre Functions and Recursions Theory, criado por Sneha Supriya em 31-07-2019.
Sneha Supriya
FlashCards por Sneha Supriya, atualizado more than 1 year ago
Sneha Supriya
Criado por Sneha Supriya mais de 5 anos atrás
11
0

Resumo de Recurso

Questão Responda
Function Definition A group of statements written for executing a specific task.
Perks of using functions 1. can be reused(need to be called and can be called again and again) 2. long programs can be broken down and can be organised using functions 3. Provides structure to program 4.Reduces program size 5.Improves readability
Types of functions Built-in Modules User-defined
What are built in functions? Stored in standard library. Needs no importation. Makes programming easier, powerful, simpler.
Name six type conversion built in functions int() str() float() list() tuple() dict() (ord(), hex()...)
what does input() built in function do? Takes input from user as a string
What does eval() built in function do? Evaluates value of string
What does min and max function do? Gives min and max values
What does abs() do? Gives absolute value (positive)
What does type(), len(), round() built-in functions do? type(): Returns type of variable len(): Returns length of function round(x,y): x gets rounded to the extent y eg. round(11.345, 2) >>>11.34
What does range() do? range(start,stop,skip) Returns series of numbers between start and stop. Also values can be skipped and returned optionally, by giving skip value.
What are python modules? Simple python(.py) files. In which functions and variables are defined. Can be called in another python file.
What does following functions of math module do? Ceil(x) floor(x) pow(x,n) sqrt(x) log10(x) cos(x) sin(x) tan(x) -ceil(x) gives >or= number to x – floor(x) returns integer smaller than x or x integer. – pow(x, n) returns x^n – sqrt(x) returns square root of x. – log10(x) returns logarithm of x with base-10 – cos(x) returns cosine of x in radians. – sin(x) returns sine of x in radians. – tan(x) returns tangent of x in radians.
how are a module's details called? help()
What does the following functions of string module do? – String.capitalize() – String.find() – String.index() – String.isalnum() – String.isalpha() – String.isdigit() – String.islower() – String.isupper() – String.join() – String.lower() – String.upper() – len() – ord() – reversed() – slice() – String.capitalize() Converts first character to Capital Letter – String.find() Returns the Lowest Index of Substring – String.index() Returns Index of Substring – String.isalnum() Checks Alphanumeric Character – String.isalpha() Checks if All Characters are Alphabets – String.isdigit() Checks Digit Characters – String.islower() Checks if all Alphabets in a String, are Lowercase – String.isupper() returns if all characters are uppercase characters – String.join() Returns a Concatenated String – String.lower() returns lowercased string – String.upper()returns uppercased string – len()Returns Length of an Object – ord()returns Unicode code point for Unicode character – reversed()returns reversed iterator of a sequence – slice()creates a slice object specified by range()
what does randrange() do? randrange (): This method always returns any integer between given lower and upper limit to this method. default lower value is zero (0) and upper value is one(1).
random () This generates floating value between 0 and 1. it does not require any argument.
What does randint () do? This method takes 2 parameters a,b in which first one is lower and second is upper limit. This may return any number between these two numbers including both limits. This method is very useful for guessing applications.
What does uniform() do? uniform (): This method return any floating-point number between two given numbers.
What does random.choice(lst) do? this method is used for random selection from list, tuple or string.
What does random.shuffle(lst) do? this method can shuffle or swap the items of a given list.
What are user defined functions? These are the functions which are made by user as per the requirement of the user.
What are parameters in a user defined function? When we write header of any function then the one or more values given to its parenthesis ( ) are known as parameter
What are arguments in user defined functions? argument is the value passed at the time of calling a function. • In other words the arguments are used to invoke a function.
What four arguments python supports? 1. Positional Arguments 2. Default Arguments 3. Keyword Arguments 4. Variable Length Arguments
What are positional arguments? Positional Arguments • These are the arguments which are passed( arguments must be passed for all parameters) in correct positional order in function. • If we change the position of the arguments then the answer will be changed.
What are Default arguments? Default Arguments • These are the arguments through which we can provide default values to the function. • If we don’t pass any value to the function then it will take a pre defined value.
What are Keyword arguments? Keyword Arguments • If a function have many arguments and we want to change the sequence of them then we have to use keyword arguments. • Biggest benefit of keyword argument is that we need not to remember the position of the argument. • For this whenever we pass the values to the function then we pass the values with the argument name.
What are Variable Length Arguments? Variable Length Arguments • As we can assume by the name that we can pass any number of arguments according to the requirement. Such arguments are known as variable length arguments. • We use (*) asterik to give Variable length argument.
What are global variables? Global (module) – All those names which are assigned at top level in module or directly assigned in interpreter.
What are local variables? Local (function) – Those variables which are assigned within a loop or function.
What's Recursion? Recursion is a set of code in which a function keeps calling itself till the condition is satisfied.
Point out some drawbacks of recursion. • It uses more storage as each values is pushed in to stack. • If recursive call is not checked carefully then your computer may go out of memory. • It is less efficient in terms of time and speed.
What is indirect recursion? if a function calls another function which calls its caller function
Perks of recursions? Recursion is a technique by which we can solve big computational problems and this repeated calling, decreases the complexity of that problem.
What's a 'correct' and 'sensible' recursive code? Recursive Function • A correct and sensible recursive code fulfills following requirements- • It requires a case which contain recursive calling. This base case should be reachable to given parameter / argument. It can be termed as stopping case which is essential to have. • It has a recursive case in which function calls itself.
How a Recursive Function works? • In such type of execution, computer sets a stack which is known as function stack. • This function stack is a stack of frames. • At every call of function, new parameter value gets pushed to the stack. The top of the stack always contains parameter value of last call. • When base case evaluates to true, values from stack needs to pop out one by one and result is to be returned after calculation
3 differences b/w iteration and recursion
Define Base Case Any line where Recursive function does not invoke itself.

Semelhante

Code Challenge Flow Chart
Charlotte Hilton
Flvs foundations of programming dba 2
mariaha vassar
psycholgoy as level topic 2 - memory
Talya Hambling
EDEXCEL IGCSE (9-1) COMPUTER SCIENCE
CreativeKai 03
Chapter 10: Medical coding
Kelly Martin
Basic Python - Strings
Rebecca Noel
Our Story
Natalia R
Coding Test!
vapetrop
HTML Tags Mindmap
Julia C.Wozniak
Operating Systems (OS)
rwc.carlton