-
-
Save mikezink/4bb2bbfc65d995141a0e8aa4bb6e0427 to your computer and use it in GitHub Desktop.
HW1 Q2 Fall 2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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