Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. class Poly:
  2.     def __init__(self, list):
  3.         if Poly.validate_input(list):
  4.             self.list = list
  5.         else:
  6.             raise Exception("Invalid input")
  7.  
  8.     @staticmethod
  9.     def validate_input(args):
  10.         """Check if the argument is a nonempty list of numbers"""
  11.         if args and isinstance(args, list) and all([isinstance(arg, int) or isinstance(arg, float) for arg in args]):
  12.             return True
  13.         else:
  14.             return False
  15.  
  16.     def order(self):
  17.         """Return the order of the polynomial."""
  18.         if self.list != [0]:
  19.             return len(self.list) - 1
  20.         else:
  21.             raise Exception("Zero polynomial.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement