top of page
Writer's pictureNerdZone

Python Programming: Write a code to convert any number into binary

“Computer Science is foundational.” Coding is considered to be the forefront of future career opportunities. Learning to code is similar to learning a new language and languages enhance our logical thinking power. How about starting an amazing and bloomed coding or rather programming language Python to convert a number from decimal to its binary form.



Introduction:


Learning to code improves mathematics skills, teaches organizations as well as foster creativity. This challenge of implementing a simple program will also enable kids to advance their problem-solving techniques along with learning fundamentals of coding in any language.


Requirements:

Pseudocode:

Function: convert a digital number into a binary number
 
DectoBin(number):
       if number > 1:
           DecToBin(number // 2)
           print(number % 2)

Example:

Input: Decimal Number 17

17 // 2 : Quotient 8 Remainder 1
8  //  2 : Quotient 4 Remainder 0
4  //  2 : Quotient 2 Remainder 0
2  //  2 : Quotient 1 Remainder 0
1  //  2 : Quotient 0 Remainder 1

Output: Binary Number 10001

Learning Opportunity:

  • Programming Languages are a way to give instructions to computers that they may understand

  • Python is a powerful, easy-to-read, high-level programming language

  • Python is a language which is used to power the technology such as web developments, data science, machine learning and applications

  • The function is a recursive function

  • Recursion is a word from Mathematics

  • A recursive function is a function which calls itself

Time Required: 10 minutes


Cost: NIL


Demo:




61 views0 comments

Recent Posts

See All

Comments


bottom of page