Answer on Question #62195 - Programming & Computer Science - Python
-*- coding: utf-8 -*-
# recursive function
def replicate_recur(a, b):
# checking for correctness of 'a' type
if not isinstance(a, int):
raise ValueError
# exit from function
if a <= 0:
return None
if a == 1:
return b
res = replicate_recur(a - 1, b)
res += b
# returning of result
return res
# iterative function
def replicate_iter(a, b):
# checking for correctness of 'a' type
if not isinstance(a, int):
raise ValueError
# exit from function
if a <= 0:
return None
res = b
for i in range(1, a):
res += b
return res
a, b = (3, "a")
try:
print(replicate_recur(a, b))
except ValueError:
print("Wrong 'a' type")
try:
print(replicate_iter(a, b))
except ValueError:
print("Wrong 'a' type")http://www.AssignmentExpert.com
Comments
Dear visitor, please use panel for submitting new questions
Suppose you have the following list of numbers to sort: [11, 7, 12, 14, 19, 1, 6, 18, 8, 20] which list represents the partially sorted list after three complete passes of selection sort? (nb: start with the largest item)
Given the following list of numbers: [21, 1, 26, 45, 29, 28, 2, 9, 16, 49, 39, 27, 43, 34, 46, 40] which answer illustrates the list to be sorted after 2 recursive calls to mergesort?
Create a class called BankAccount that has the methods withdraw and deposit with no implementation. Create a class called SavingsAccount that inherits from BankAccount. SavingsAccount should have a constructor that only takes in a self argument. This constructor sets a property called balance to 500. (This should be the minimum balance at any given time).