In: Computer Science
I understand most of this information is more suitable to C++ but our instructor wants us to modify it to do it in Python. As long as you fufill the parameters the best you can in Python and works that all I want. Thank you
Grading:
Please do this in PYTHON to the best of ones ability. Just try to fufill all the requirements in PYTHON as best you can.
My lab one python code
class Dollar:
def _init_(self):
__whole = 0
__fract = 0
__name = ''
def _init_(self, whole, fract, name):
self.__whole = whole
self.__fract = fract
self.__name = name
def set_whole(self, whole):
self.__whole = whole
def set_fractional(self, fractional):
self.__fract = fractional
def set_name(self, name):
self.__name = name
def get_whole(self):
return self.__whole
def get_fractional(self):
return self.__fract
def get_name(self):
return self.__name
def _del_():
print("Destructor called!")
def add_sameCurrency(self, node):
fract = self._fract + node._fract
if fract > 99:
wholePart = fract // 100
fract = fract % 100
whole = self._whole + node._whole + wholePart
return whole, fract
# Subtraction same currency
def sub_sameCurrency(self, node):
fract = 0
whole = 0
if self._fract >= node._fract:
fract = self._fract - node._fract
else:
fract = self._fract - node._fract + 100
whole = self.__whole - 1
whole += self._whole - node._whole
return whole, fract
# Checking equality/inequality
def is_equal(self, node):
if self._name == node._name:
if self.__whole == node.whole:
if self._fract == node._fract:
return True
else:
return False
else:
return False
else:
return False
# comapring same currency
def is_greater(self, node):
if self._whole > node._whole:
return True
elif self._whole == node._whole:
if self._fract > node._fract:
return True
else:
return False
def show(self):
print('The amount is: ', self._whole, '.', self._fract, ' ',
self._name)
def C2D2USD(self):
self._fract = (0.74 * self._fract)
self._whole = (0.74 * self._whole)
if self.__fract > 99:
self._fract = self._fract % 10
self._whole += self._fract // 100
self.__name = 'USD'
return self
# 1000 fract = 1 whole
# 1 USD = 1.36 C2D
# 1 C2D = 0.74 USD
class CIS22C:
def _init_(self):
__whole = 0
__fract = 0
__name = ''
def _init_(self, whole, fract, name):
self.__whole = whole
self.__fract = fract
self.__name = name
# Setters and Getters
def set_whole(self, whole):
self.__whole = whole
def set_fractional(self, fractional):
self.__fract = fractional
def set_name(self, name):
self.__name = name
def get_whole(self):
return self.__whole
def get_fractional(self):
return self.__fract
def get_name(self):
return self.__name
# Destructor
def _del_():
print("Destructor called!")
# Adding same currency
def add_sameCurrency(self, node):
fract = self._fract + node._fract
if fract > 99:
wholePart = fract // 1000
fract = fract % 1000
whole = self._whole + node._whole + wholePart
return whole, fract
# Subtraction same currency
def sub_sameCurrency(self, node):
fract = 0
whole = 0
if self._fract >= node._fract:
fract = self._fract - node._fract
else:
fract = self._fract - node._fract + 1000
whole = self.__whole - 1
whole += self._whole - node._whole
return whole, fract
# Checking equality/inequality
def is_equal(self, node):
if self._name == node._name:
if self.__whole == node.whole:
if self._fract == node._fract:
return True
else:
return False
else:
return False
else:
return False
# comapring same currency
def is_greater(self, node):
if self._whole > node._whole:
return True
elif self._whole == node._whole:
if self._fract > node._fract:
return True
else:
return False
def show(self):
print('The amount is: ', self._whole, '.', self.fract, ' ',
self._name)
def USD2C2D(self):
self._fract = 1.36 * self.fract
self._whole = 1.36 * self._whole
if self.__fract > 999:
self._fract = self._fract % 100
self._whole += self._fract // 1000
self.__name = 'C2D'
return self
class Wallet:
def _init_(self):
array = [0, 0]
dol = Dollar(0, 0, 'USD')
array[0] = dol
c2d = CIS22C(0, 0, 'C2D')
array[1] = c2d
def _init_(self, whole, fract, name):
array = [0, 0]
if name == 'USD':
dol = Dollar(whole, fract, name)
array[0] = dol
else:
c2d = CIS22C(whole, fract, name)
array[1] = c2d
def _del_(self):
print('The object is deleted!')
def addUSD(self, node):
self[0] = self[0].add_sameCurrency(node)
def addC2D(self, node):
self[1] = self[1].add_sameCurrency(node)
def subUSD(self, node):
self[0] = self[0].sub_sameCurrency(node)
def subC2D(self, node):
self[1] = self[1].sub_sameCurrency(node)
def compareUSD(self, node):
if not self[0].is_equal(node):
if self[0].is_greater(node):
print("Greater")
else:
print("smaller")
else:
print('Equal')
def compareC2D(self, node):
if not self[1].is_equal(node):
if self[1].is_greater(node):
print("Greater")
else:
print("smaller")
else:
print('Equal')
SOLUTION :
CONSIDERING THE CONDITIONS AND PARAMETERS AND REQUIREMENTS FROM THE QUESTION
HERE CODE:
# function is used to check whether a given number or not using iteration
def isPrime(n):
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False;
return True
# function is used to check whether a given list has all prime
numbers or not using iteration
def check_list_prime_iteration(arr,le):
count=0
for i in arr:
if(isPrime(i)):
count=count+1
if(count==le):
return True
else:
return False
# function is used to check whether a given list has all prime numbers or not using recusrion
def check_list_prime_recursion(arr,le):
count=0
for i in arr:
if(isPrime_Rec(i)):
count=count+1
if(count==le):
return True
else:
return False
# function is used to check whether a given number or not using recusrion
def isPrime_Rec(n, i = 2):
if (n <= 2):
return True if(n == 2) else False
if (n % i == 0):
return False
if (i * i > n):
return True
return isPrime_Rec(n, i + 1)
# List to store values
l=[]
i=1
# input taking
n=int(input("Enter size of an Array"))
while(i<=n):
input_value=int(input("Enter number"))
if(input_value>=1 and input_value<=99):
l.append(input_value)
else:
print("please enter valid input between 1 and 99")
i=i-1
i=i+1
# Final list after validation
print("Array List",l)
if check_list_prime_iteration(l,len(l)):
print("Prime Array using iteration")
else:
print("Not a Prime Array using iteration")
if check_list_prime_recursion(l,len(l)):
print("Prime Array using recursion")
else:
print("Not a Prime Array using recursion")
OUTPUT :
NOTE: PLEASE UPVOTE ITS VERY MUCH NECESSARY FOR ME A LOT. PLEASE......