[英]Need to subtract and remove leading zeros
在下面的程序中,我需要從變量“ 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
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.