1

わかりましたので、これについて数日間机の上で頭を悩ませましたが、まだ取得できません。この問題が発生し続けています。

Traceback (most recent call last):
  File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 44, in <module>
  File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 35, in main
  File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 15, in __init__
builtins.TypeError: can't multiply sequence by non-int of type 'float'

何度も。私は壁にぶつかったと思いますが、実際にかなりの量の調査とテストを行いましたが、誰かが私を正しい方向に向けることができれば、それは大歓迎です.

from math import pi, sin, cos, radians

def getInputs():
    a = input("Enter the launch angle (in degrees): ")
    v = input("Enter the initial velocity (in meters/sec): ")
    h = input("Enter the initial height (in meters): ")
    t = input("Enter the time interval between position calculations: ")
    return a,v,h,t
class Projectile:

    def __init__(self, angle, velocity, height):

        self.xpos = 0.0
        self.ypos = height
        theta =  pi *(angle)/180
        self.xvel = velocity * cos(theta)
        self.yvel = velocity * sin(theta)

    def update(self, time):
        self.xpos = self.xpos + time * self.xvel
        yvel1 = self.yvel - 9.8 * time
        self.ypos = self.ypos + time * (self.yvel + yvel1) / 2.0
        self.yvel = yvel1

    def getY(self):
        "Returns the y position (height) of this projectile."
        return self.ypos

    def getX(self):
        "Returns the x position (distance) of this projectile."
        return self.xpos

def main():
    a, v, h, t = getInputs()
    cball = Projectile(a, v, h)
    zenith = cball.getY()
    while cball.getY() >= 0:
        cball.update(t)
        if cball.getY() > zenith:
            zenith = cball.getY()
    print ("/n Distance traveled: {%0.1f} meters." % (cball.getY()))
    print ("The heighest the cannon ball reached was %0.1f meters." % (zenith))

if __name__ == "__main__": main()
4

1 に答える 1