我試圖從一個元組中獲取第100個整數。現在的問題有云:從一個元組獲取第100個整數(python)
Implement a function
get_hundredth(a, b, c)
that takes in 3 positive integers as arguments and returns a tuple of digits at the respective hundredth position.If a given integer is less than 100, its hundredth position can be viewed as 0. If the input is invalid, return
None
for that integer.
get_hundredth(1234, 509, 80633)
should return(2, 5, 6)
andget_hundredth(4024, 81, 2713)
should return(0, 0, 7)
這是我到目前爲止有:
def get_hundredth(a, b, c):
a, b, c = str(a), str(b), str(c)
return int(a[-3:-2]), int(b[-3:-2]), int(c[-3:-2])
我怎麼讓它爲0,如果是100下?
我想你混淆「百分之一」與「數百名」 –
如果被「噓」,你會返回「b」。那真的好嗎? – hruske