简体   繁体   English

需要减去并删除前导零

[英]Need to subtract and remove leading zeros

In the following program, I need to subtract the bartype from the variable "b" and then in one section of code remove leading zeros from 2.5 在下面的程序中,我需要从变量“ b”中减去条形,然后在代码的一部分中从2.5中删除前导零。

I have tried moving the subtraction around in different places of the code 我试图在代码的不同位置移动减法

b=int(input('Please enter weight to load on the bar:'))
bartype=int(input('Please enter bar weight'))
x = bartype
b = (b-x)
print(b//45, "45's")
b = b%45
print(b//25, "25's")
b = b%25
print(b//10, "10's")
b = b%10
# I need to print 2.5 without leading zeros
print(b/2.5, "2.5's")
b = b%2.5

print(b//5, "5's")
b = b%5

So here is an example 365 = 365 - bartype and then weight types ( 45, 25, etc) should be broken down. 因此,这里有一个示例365 = 365-条形,然后应分解重量类型(45、25等)。 The answer should be 6 45's 2 25's. 答案应该是6 45的2 25的。 example 320 should equal 6 45's and 2 2.5's 示例320应该等于6 45和2 2.5

b = int(input('Please enter weight to load on the bar :  '))-int(input('Please enter bar weight :  '))
print(int(b//45), "45's") # int() to convert float value to int
b = b%45
print(int(b//25), "25's")
b = b%25
print(int(b//10), "10's")
b = b%10
# I need to print 2.5 without leading zeros
print(int(b/2.5), "2.5's")
b = b%2.5
print(int(b//5), "5's")
b = b%5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM