+ 6

Can anyone help me??

read this program--- def oct2(n): print("passed octal no.:",n) n=str(n) decNum=int(n,8) print("Number in Decimal:",decNum) print("Number in Hexadecimal:", hex(decNum)) print("Number in Binary:", bin(decNum)) num=int(input("Enter an octal number:")) oct2(num) Here, what is the use of decNum=int(n,8) I can't understand. Can anyone help me??

27th Apr 2019, 1:28 PM
ANU
ANU - avatar
6 ответов
+ 9
There are 4 main systems of representing numbers: - Decimal numbers (base 10) - Hexadecimal numbers (base 16) - Binary numbers (base 2) - Octal numbers (base 8) In Python, the `int()` function is defined as: def int(str, base=10): # ... It receives a string value and an optional base, which defaults to 10. Basically, all it does is it converts a string into a number. The number is formatted with the base as its rule. int("10", 8) Will output 8 because it is base 8 (or an Octal value)
27th Apr 2019, 1:40 PM
Edwin Pratt
Edwin Pratt - avatar
+ 6
It is a pleasure 😊
28th Apr 2019, 11:56 AM
Edwin Pratt
Edwin Pratt - avatar
+ 4
Diego ooh sorry, did quick math 😶🙂
27th Apr 2019, 1:56 PM
Edwin Pratt
Edwin Pratt - avatar
+ 4
Thank you Gordon and Edwin Pratt. Thank u soo much.
28th Apr 2019, 11:26 AM
ANU
ANU - avatar
+ 2
Treating the string as a number under octal number system (base 8), and converts into int of decimal system (base 10) https://code.sololearn.com/cTB38H7UyEfD/?ref=app
27th Apr 2019, 1:37 PM
Gordon
Gordon - avatar
+ 2
Edwin Pratt int("10", 8) will output 8, not 13.
27th Apr 2019, 1:54 PM
Diego
Diego - avatar