Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Need To Use Python To Make A Calculator For IVT

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.html

Figured it out, here you go.
[Image: xwnI9Yg.png]
I'd like to recommend following pep8 as your python style guide (https://www.python.org/dev/peps/pep-0008/).


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 630 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by TISADec 2, 2017 09:03 AM 4 237 Dec 2, 2017 09:03 AM
Last Post: Gliese
[Python] by Mimzie5Feb 3, 2017 06:35 PM 3 129 Feb 3, 2017 06:35 PM
Last Post: SIM-1866423