Chapter 03
Chapter 03
Chapter 3
Computing with Numbers
b b 2 4ac
x
2a
• The only part of this we don’t know how to
do is find a square root… but it’s in the
math library!
def main():
print("This program finds the real solutions to a quadratic")
print()
discRoot = math.sqrt(b * b - 4 * a * c)
root1 = (-b + discRoot) / (2 * a)
root2 = (-b - discRoot) / (2 * a)
print()
print("The solutions are:", root1, root2 )
main()
def main():
n = eval(input("Please enter a whole number: "))
fact = 1
for factor in range(n,1,-1):
fact = fact * factor
print("The factorial of", n, "is", fact)
main()