-1
Как я могу отредактировать свою программу без заявления if
?Отскок мяча без, если в python
from visual import *
display(title='BasicEdit', x=0, y=0, fullscreen=True,
center=(0,0,0), range=(10,10,10),
background=(0,0,0))
x_axis = arrow(pos=(0,0,0), axis = vector(3,0,0), color=color.green)
y_axis = arrow (pos=(0,0,0), axis = vector(0,3,0), color=color.red)
z_axis = arrow(pos=(0,0,0), axis = vector(0,0,3), color=color.cyan)
ball = sphere(pos=(0,4,0), radius = 0.4, color=color.red)
ball.velocity = vector(0,-1,0)
ground = box(pos = (0,-0.1,0), lenght = 50, height = 0.1, width = 50)
dt = 0.01
while 1:
rate(100)
ball.pos = ball.pos + ball.velocity*dt
if ball.y < 1:
ball.velocity.y = -ball.velocity.y
else:
ball.velocity.y = ball.velocity.y - 9.8*dt
Вы хотите удалить 'если/else' условие из вашего кода сохраняя логику же? –