def binary_to_decimal(n): #Function which convert binary to decimal num = n; dec_value = 0; base = 1; # Initializing base temp = num; while(temp): last_digit = temp % 10; temp = int(temp / 10); dec_value += last_digit * base; base = base * 2; return dec_value; #_____main_____ number=int(input("Please enter a number in binary: ")) print(binary_to_decimal(number)); Output 1: Please enter a number in binary: 101 5 Output 2: Please enter a number in binary: 1110010 114 Output 3: Please enter a number in binary: 100101011 299
इन्हें भी देखें।
- while loop
- for loop
- nested loops
- loop control statements (Break, Continue, Pass)
- if statement
- if-else statement
- if-elif statement
- nested if statement
- range() function
- keywords
- Identifiers (names)
- Literals
- Operators
- punctuatorts
Python Programs के लिये यहाँ click करें।