1. Program:
def countdown (n):
if n <= 0:
print('Blastoff !')
else:
print(n)
countdown(n-1)
def countup(n):
if n >= 0:
print('Blastoff !')
else:
print(n)
countup(n+1)
n = int(input('Enter Number'))
if n > 0:
(countdown(n))
elif n < 0:
(countup(n))
else:
(countdown(0))
Output for Negative Input:
Enter Number-5
-5
-4
-3
-2
-1
Blastoff !
Output for Positive Input:
Enter Number5
5
4
3
2
1
, Blastoff !
Output for Zero input:
Enter Number0
Blastoff !
Explanation:
In this program I chose countdown as a function call for input of zero because I think
zero is very close to the countdown function as all numbers which are greater than zero
eventually decrease when countdown function is called.
2. Program:
>>> x = 12
>>> y = 6
>>> z = x * y * math.pi
Output:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
z = x * y * math.pi
NameError: name 'math' is not defined
Explanation:
In this program we encounter with runtime error known as NameError which tells us that
we didn’t define math in the program so python doesn’t know what to do with math and
it gives us runtime error. In the program math was supposed to be imported module to
solve mathematical functions but we didn’t import or define it so python can’t handle
such operations.
Solution:
The solution to solve this runtime error is to import math module in the program using
import math code so that it can handle with mathematical functions of any kind like pi in
this program.
References:
1. Chained conditional: In python we often come across problems which involve many
conditions and we only want one perfect answer from these possibilities. Chained
conditional allows us to add more than two conditions or alternatives which are called
branches and only that branch is executed which equals to the desire outcome ‘True’.
Example:
def relation(x,y):
if x == 'James mark' and y == 'Sam mark':
print(x, y,'are brothers')
elif x == 'James mark' and y == 'William will':
print(x, y, 'are cousins')
def countdown (n):
if n <= 0:
print('Blastoff !')
else:
print(n)
countdown(n-1)
def countup(n):
if n >= 0:
print('Blastoff !')
else:
print(n)
countup(n+1)
n = int(input('Enter Number'))
if n > 0:
(countdown(n))
elif n < 0:
(countup(n))
else:
(countdown(0))
Output for Negative Input:
Enter Number-5
-5
-4
-3
-2
-1
Blastoff !
Output for Positive Input:
Enter Number5
5
4
3
2
1
, Blastoff !
Output for Zero input:
Enter Number0
Blastoff !
Explanation:
In this program I chose countdown as a function call for input of zero because I think
zero is very close to the countdown function as all numbers which are greater than zero
eventually decrease when countdown function is called.
2. Program:
>>> x = 12
>>> y = 6
>>> z = x * y * math.pi
Output:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
z = x * y * math.pi
NameError: name 'math' is not defined
Explanation:
In this program we encounter with runtime error known as NameError which tells us that
we didn’t define math in the program so python doesn’t know what to do with math and
it gives us runtime error. In the program math was supposed to be imported module to
solve mathematical functions but we didn’t import or define it so python can’t handle
such operations.
Solution:
The solution to solve this runtime error is to import math module in the program using
import math code so that it can handle with mathematical functions of any kind like pi in
this program.
References:
1. Chained conditional: In python we often come across problems which involve many
conditions and we only want one perfect answer from these possibilities. Chained
conditional allows us to add more than two conditions or alternatives which are called
branches and only that branch is executed which equals to the desire outcome ‘True’.
Example:
def relation(x,y):
if x == 'James mark' and y == 'Sam mark':
print(x, y,'are brothers')
elif x == 'James mark' and y == 'William will':
print(x, y, 'are cousins')