Skip to content

Instantly share code, notes, and snippets.

@mikezink
Created September 15, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikezink/4bb2bbfc65d995141a0e8aa4bb6e0427 to your computer and use it in GitHub Desktop.
Save mikezink/4bb2bbfc65d995141a0e8aa4bb6e0427 to your computer and use it in GitHub Desktop.
HW1 Q2 Fall 2020
class Hw1Q2:
def __init__(self):
# gathers a, b and c from inputs
self.a = float(input('enter value for a: '))
self.b = float(input('enter value for b: '))
self.c = float(input('enter value for c: '))
def monomial(self): #solves monomial
x = (self.c-self.b)/self.a
result = str(self.a)
if self.b > 0:
result += 'x + ' + str(self.b)
elif self.b < 0:
result += 'x - ' + str(-self.b)
print(result + ' = ' + str(self.c)) # print equation
print('x = ' + str(x)) # print result
def polynomial(self):#solves polynomial
self.n = float(input('enter value for n: '))
x = (self.c**(1/self.n) - self.b)/self.a
result = '(' + str(self.a)
if self.b > 0:
result += 'x + ' + str(self.b)
elif self.b < 0:
result += 'x - ' + str(-self.b)
print(result + ')^' + str(self.n) + ' = ' + str(self.c)) # print equation
print('x = ' + str(x)) # print result
a1 = Hw1Q2()
a1.monomial()
a2 = Hw1Q2()
a2.polynomial()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment