import random
class RandomNumbers:
def __init__(self, start, end):
self.start = start
self.end = end
self.random_number = random.randint(self.start, self.end)
def get_random_number(self):
return self.random_number
class RandomNumbersSum(RandomNumbers):
super().__init__(start, end)
self.random_number_2 = random.randint(self.start, self.end)
def get_random_number_2(self):
return self.random_number_2
def get_sum(self):
return self.random_number + self.random_number_2
class RandomNumbersProduct(RandomNumbers):
def get_product(self):
return self.random_number * self.random_number_2
if __name__ == "__main__":
random_numbers_sum = RandomNumbersSum(7, 15)
random_numbers_product = RandomNumbersProduct(7, 15)
if random_numbers_sum.get_sum() > 17:
print(random_numbers_sum.get_random_number() + random_numbers_sum.get_random_number_2())
else:
print(random_numbers_product.get_random_number() * random_numbers_product.get_random_number_2())
Copyright © 2025 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
import random
class RandomNumbers:
def __init__(self, start, end):
self.start = start
self.end = end
self.random_number = random.randint(self.start, self.end)
def get_random_number(self):
return self.random_number
class RandomNumbersSum(RandomNumbers):
def __init__(self, start, end):
super().__init__(start, end)
self.random_number_2 = random.randint(self.start, self.end)
def get_random_number_2(self):
return self.random_number_2
def get_sum(self):
return self.random_number + self.random_number_2
class RandomNumbersProduct(RandomNumbers):
def __init__(self, start, end):
super().__init__(start, end)
self.random_number_2 = random.randint(self.start, self.end)
def get_random_number_2(self):
return self.random_number_2
def get_product(self):
return self.random_number * self.random_number_2
if __name__ == "__main__":
random_numbers_sum = RandomNumbersSum(7, 15)
random_numbers_product = RandomNumbersProduct(7, 15)
if random_numbers_sum.get_sum() > 17:
print(random_numbers_sum.get_random_number() + random_numbers_sum.get_random_number_2())
else:
print(random_numbers_product.get_random_number() * random_numbers_product.get_random_number_2())