May 26, 2017 04:57 PM
(This post was last modified: May 26, 2017 07:39 PM by Linxy.)
Code
# QUICK OVERVIEW
# One = means I'm defining something Ex. a = 2 means I'm defining a to be equal to 2.
# Two ='s means I'm comparing something Ex 2 == 2 means I'm seeing if 2 is equal to 2.
# Two *'s means I'm going to the power of some number. Ex. 3 ** 6 is 3^6.
# MRW I'm In Calculus
# https://i.imgur.com/q2MP6O0.gifv
# Lines 10 - 21 is the equivalent of adding 14px periods to your paper.
answer = input("Do you know what IVT is? Yes or No: ")
if answer == "Yes":
print("I'm telling you anyway.")
else:
print("Well here's the definition!")
# What is IVT???
print("The intermediate value theorem states that if a continuous function, f, with an interval, [a, b] ")
print("as its domain, takes values f(a) and f(b) at each end of the interval, then it also takes any value between f(a) ")
print("and f(b) at some point within the interval.")
# Okay Let's Try it
# What could go wrong???
# Voodoo Magic - This was the hardest part to do. Don't question it, because I don't know either.
def read_user_function():
function_str = input("Enter your Function: ")
return lambda x: eval(function_str, {'x': x})
# Define funciton f
f = read_user_function()
# Retrieve lower bound.
a = input("Enter the value of a: ")
# Transform answer into an integer.
a = int(a)
#R etrieve upper bound.
b = input("Enter the value of b: ")
# Transform answer into an integer.
b = int(b)
# Run a through the function.
a_Applied = f(a)
# Print what f(a) is equal too.
print("f(a) is equal to " + str(a_Applied))
# Run b through the funciton.
b_Applied = f(b)
# Print what f(b) is equal too.
print("f(b) is equal to " + str(b_Applied))
# Run a series of tests to see if IVT Applies
if a_Applied < 0 and b_Applied > 0:
print("IVT applies on this interval.")
elif a_Applied > 0 and b_Applied < 0:
print("IVT applies on this interval.")
elif a_Applied == 0 or b_Applied == 0:
print("IVT applies on this interval.")
else:
print("IVT does not apply on this interval.")
# Mr. Ritsick Wanted A UI.
# Pfffffft
# Where I learned --> https://learnpythonthehardway.org/book/intro.htmlFigured it out, here you go.
![[Image: xwnI9Yg.png]](https://i.imgur.com/xwnI9Yg.png)


