Every recursive function must have a base case
Infinite recursion can occur if the base case isn’t properly mentioned
A recursive function makes the code easier to understand
Every recursive function must have a return value
What will be the output of the following Python code?
def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))
50
100
74
Infinite loop
Program gets into an infinite loop
Program runs once
Program runs n number of times where n is the argument given to the function
An exception is thrown
Making the code look clean
A complex task can be broken into sub-problems
Recursive calls take up less memory
Sequence generation is easier than a nested iteration
It’s easier to code some real-world problems using recursion than non-recursive equivalent
Recursive functions are easy to debug
Recursive calls take up a lot of memory
Programs using recursion take longer time than their non-recursive equivalent
def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2) for i in range(0,4): print(a(i),end=" ")
0 1 2 3
0 1 1 2 3
0 1 1 2
import datetime d=datetime.date(2017,6,18) print(d)
Error
2017-06-18
18-06-2017
06-18-2017
What will be the output of the following Python code if the system date is 18th August, 2016?
import datetime d=datetime.date.today() print(d.month)
August
Aug
08
8
What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?
import datetime
tday=datetime.date.today()
print(tday)
print(tday.weekday())
6
1
0
7
What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday)?
import datetime tday=datetime.date.today() print(tday.isoweekday())
Wed
Wednesday
2
3
Which of the following will throw an error if used after the following Python code?
bday=datetime.date(2017,9,18)
t_day=bday-tday
print(t_day.seconds)
print(t_day.months)
print(t_day.max)
print(t_day.resolution)
What will be the output of the following Python code if the system date is: 6/19/2017
tdelta=datetime.timedelta(days=10)
print(tday+tdelta)
2017-16-19
2017-06-9
2017-06-29
datetime.utc()
datetime.datetime.utc()
datetime.utcnow()
datetime.datetime.utcnow()
import time
time.time()
The number of hours passed since 1st January, 1970
The number of days passed since 1st January, 1970
The number of seconds passed since 1st January, 1970
The number of minutes passed since 1st January, 1970
time.asctime()
Current date only
UTC time
Current date and time
Current time only
t=(2010, 9, 20, 8, 15, 12, 6)
time.asctime(t)
‘20 Sep 2010 8:15:12 Sun’
‘2010 20 Sept 08:15:12 Sun’
‘Sun Sept 20 8:15:12 2010’
t=(2010, 9, 20, 8, 45, 12, 6, 0, 0)
‘Sep 20 2010 08:45:12 Sun’
‘Sun Sep 20 08:45:12 2010’
’20 Sep 08:45:12 Sun 2010’
‘2010 20 Sep 08:45:12 Sun’
Pause the code for the specified number of seconds
Return the specified number of seconds, in terms of milliseconds
Stop the execution of the code
Return the output of the code had it been executed earlier by the specified number of seconds
import random
random.h
import.random
random.random