import math
def main():
input(a,b,n,dx)
sum=0
for count in range(n):
sum+=dist(a+(dx*count), a+(dx*(count+1)))
print("Sum of lengths = ", sum)
def input(a,b,n,dx):
a = float(input("Value for a: "))
b = float(input("Value for b: "))
n = float(input("Value for n: "))
dx = (b-a)/n
def f(x):
return math.cos(x)
def dist(a,B)/>:
d = (math.sqrt( (b-a)** + (f(B)/>-f(a))**)
return d
main()
Correction, at the end of the line where I call the math.sqrt function. OH, also how do I input several variables from the user in one line? In C++ I'm used to doing it like "cin >> a, b, n", in python i'm guessing it to be something like "a,b,n=input("string"),input("string"),input("string")?

New Topic/Question
Reply



MultiQuote




|