-2

I get return of 50 whenever I set initial velocity 0, final 10 and change in time 10.

#!/usr/bin/env python3
import math
import random

motionLimitation = input("Is motion angular or linear? ")

if motionLimitation == "angular" or "Angular":
    searchField = input("What type of angular motion are you trying to calculate? (Angular, Tangential, Centripetal) ")
    
    if searchField == "Angular" or "angular":
        fieldOfMotion = input("What is the unknown value? (Displacement, Time, Acceleration, or Velocity) ")
        finalVelocity = float(input("Enter the value of final velocity. "))
        changeTime = float(input("Enter the change in time. "))
        angularAcceleration = float(input("Enter Angular Acceleration. "))
        initAngularVelocity = float(input("Enter initial Angular Velocity. "))
        averageVelocity = float((finalVelocity+initAngularVelocity)/2)
        changeVelocity = float(finalVelocity-initAngularVelocity)
        displacement = float(input("Enter Displacement. "))
        
        if fieldOfMotion == "Displacement" or "displacement":
            doubleTime = float(math.pow(changeTime, 2))
            dispOne = float(averageVelocity*changeTime)
            componentOne = float(initAngularVelocity*changeTime)
            componentTwo = float((angularAcceleration*doubleTime)/2)
            dispTwo = float(componentOne+componentTwo)
            print(dispOne)
            print(dispTwo)
            
        elif fieldOfMotion == "Acceleration" or "acceleration":
                accelerationAng = float((changeVelocity)/(changeTime))
                componentEin = float(2*(displacement-initAngularVelocity*changeTime))
                accelerationAngTwo = float(componentEin/doubleTime)
                print(accelerationAng)
                print(accelerationAngTwo)
Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • Please include some description of your code; for example, what the expected output is. – M-Chen-3 Dec 14 '20 at 18:47
  • 3
    Regarding `searchField == "Angular" or "angular"`, see https://stackoverflow.com/q/15112125/1126841. – chepner Dec 14 '20 at 18:50
  • If you just want to make the test case-insensitive, use `if motionLimitation.lower() == "angular":` – Barmar Dec 14 '20 at 18:55
  • BTW, the names of the variables look so Java-like. You might want to read the [Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/). – Matthias Dec 14 '20 at 19:00
  • @M-Chen-3 the output should be 1.0 when initAngularVelocity = 0, finalVelocity = 10, and changeTime = 10 but I get an output of 50 – empty-engineer Dec 14 '20 at 19:01

1 Answers1

0

I imagine what you are asking is, something along the lines of:

I believe that the output should be 1.0 when initAngularVelocity = 0, finalVelocity = 10, and changeTime = 10. but I am getting 50 instead.

Can someone guide me through the calculation to see where the error is.

If this is indeed what you are asking, then I think the answer is that your premise is wrong. The answer (by answer, I mean dispOne) should not be 1.0, it should be 50:

initAngularVelocity = 0
finalVelocity = 10
changeTime = 10

Therefore:

averageVelocity = float((finalVelocity+initAngularVelocity)/2)
= float(10 + 0)/2
= 5

And:

dispOne = float(averageVelocity*changeTime)
= float(5 * 10)
= 50

Hopefully this answers the question of why you are getting an answer of 50. It would appear from your question that this is not your expected answer. So, I would check the definitions of the calculated values you are assuming. I am not sure what you are trying to calculate, so I can't help here, however taking a wild guess from your variable names, I would in particular check to see if your definitions of averageVelocity and changeVelocity are what you intend.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
smurry
  • 79
  • 6
  • thank you, could I just create a library of separate functions for each calculation and then reference them to just create a simpler code? – empty-engineer Dec 15 '20 at 15:52