0
In script of reverse a number, I saw that every time i divide the number by 10, i need to use type conversion, why?
while True: print("\tReverse A Number\n") num = int(input("Enter a Number: ")) new_num = 0 print("\n") while num != 0: rem = num%10 num = int(num/10) new_num = new_num*10 + rem print("The Number After Reversal " + str(new_num)) In the second while block When i replace num = int(num/10) by num = num/10 it gives output as The Number After Reversal inf what is inf? and why this happened?
7 ответов
+ 5
Because division in python returns FLOAT
You can use floor division // . It will return integer when you will divide two integers
+ 5
inf is infinity
+ 4
So when you divide by 10 it is float => infinite loop
+ 3
@Gaurav you mean int?
If yes - it coverts float(real) number to int(only full part) also can converts strings to int
0
and what is inf stands for?
0
nope I mean inf , when you use int = int/ 10 the output you got :The Number After Reversal inf
0
OK thanks