def main():
get_variables()
def get_variables():
initial_position = float(input("Enter the object's initial position: "))
initial_velocity = float(input("Enter the object's initial velocity: "))
acceleration = float(input("Enter the object's acceleration: "))
time = float(input("Enter the time that has passed: "))
if time < 0
print('The time cannot be negative')
time = float(input('Enter a valid time: ')
#formula
position_of_object = initial_position + initial_velocity * time + 0.5 * acceleration * time ** 2
#Display Position of object
print("The position of the object is: ", position_of_object)
while keep_going == 'y'
keep_going = input("Do you want to calculate another Object's poistion?" + \
'position_of_object (Enter y for yes): ')
main()
这是我的作业,它说
&#34;如果时间&lt; 0 ^ SyntaxError:语法无效&#34;
我对编程几乎一无所知,正在上网。请告诉我哪里错了
答案 0 :(得分:0)
您的代码中似乎没有错误:
1:失踪&#34;:&#34;和&#34;)&#34;:
if time < 0
print('The time cannot be negative')
time = float(input('Enter a valid time: ')
应改为:
if time < 0:
print('The time cannot be negative')
time = float(input('Enter a valid time: '))
2:失踪&#34;:&#34;在诡计循环中:
while keep_going == 'y'
keep_going = input("Do you want to calculate another Object's
poistion?" + \
'position_of_object (Enter y for yes): ')
应改为
while keep_going == 'y':
keep_going = input("Do you want to calculate another Object's
poistion?" + \
'position_of_object (Enter y for yes): ')