在下面的程序中,我需要从变量“ b”中减去条形,然后在代码的一部分中从2.5中删除前导零
我尝试在代码的不同位置移动减法
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
因此,这是一个示例365 = 365-条形,然后应分解重量类型(45、25等)。答案应该是6 45的2 25的。示例320应该等于6个45和2个2.5
答案 0 :(得分:0)
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