+ 2
How can I improve this code ?
4 Réponses
+ 6
Arrchith ,
2 suggestions p:
(1)
the function can be shortened like:
def p(m,v):
return m*v
(2)
since the calculation is quite simple, we can do it directly in the output string:
weight = int(input())
velocity = int(input())
print(f'weight of {weight} kg and velocity of {velocity} m/s give us the momentum of {weight * velocity} kg.m/s',"\n\nCode by Arrchith")
+ 5
See this, maybe it's helpful to you
https://code.sololearn.com/cX0z5vBtCYTi/?ref=app
+ 5
# A small addition to Sakshi answer can be helpful for readability of a code:
# Modified Code:
def p(m,v):
momentum = m*v
return momentum
bulk = int(input())
velocity = int(input())
momentum = p(bulk,velocity)
print(f'Bulk of {bulk} kg and velocity of {velocity} m/s give the momentum of {momentum} kg.m/s',"\n\nCode by Arrchith")
+ 3
Thank you