首页 > 解决方案 > How can I spontaneously print a loop in function python

问题描述

so i am doing a computational physics homework, i need to make a calculator to calculate a range of number from 1 to 10 which is time (t) to my function. My code looks like this

import numpy as np
def vonx(v,theta):
    
        theta_to_radian = np.deg2rad(theta)
        vx = v*np.cos(theta_to_radian)*time

 
        return vx

so how do i spontaniously calculate this equation including time and have multiple answer?

also, can I use input to input the value of v and theta?

标签: pythonphysics

解决方案


假设您要动态打印从 0 到 10 的 vx 值:

import numpy as np

v = int(input())
theta = int(input())

def vonx(v,theta, time):
    
        theta_to_radian = np.deg2rad(theta)
        vx = v*np.cos(theta_to_radian)*time
 
        return vx

for time in range(11):
    print(vonx(v,theta,time))

推荐阅读