I have the following task, take number from input, extend it to 12 digits and then print billions, millions, thousands, hundreds and unit. I have split the number to corresponding parts as string. The code follows:
num = input("Please enter a number: ")
num = str(num)
zero = num.zfill(12)
billion = zero[0:3]
million = zero[3:6]
thousand = zero[6:9]
hundred = zero[9:10]
unit = zero[10:]
Suppose, the num is 63380.
Expected output
0 billion 0 million 63 thousand 3 hundred and 80
But I get
000 billion 000 million 063 thousand 3 hundred and 80
you can convert your
zerostring toint()like thisconverting into int do this.
3.7to3'3'to3and000000000003to3and00000to0. it deletes many zeros in the front of the numbers and convert string to int.and float(like
3.7) to int(to3) by discarding it.