TORONTO KIDS COMPUTER CLUB | Aurora Saturday 18:30 Python Homework 11.23.
16753
post-template-default,single,single-post,postid-16753,single-format-standard,ajax_fade,page_not_loaded,,no_animation_on_touch,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Aurora Saturday 18:30 Python Homework 11.23.

25 Nov Aurora Saturday 18:30 Python Homework 11.23.

Problem Description
We have learn how to use stack to solve some problems and how to convert decimal number into binary number:

Please write the program to convert a given decimal number into a binary number by using the following steps for python coding solutions:

  • takes an argument that is a decimal number and repeatedly divides it by 2.
  • uses the built-in modulo operator, %, to extract the remainder and then pushes it on the stack.
  • after the division process reaches 0, a binary string is constructed in the stack.
  • creates an empty string.
  • The binary digits are popped from the stack one at a time and appended to the right-hand end of the string.
  • the binary string is then returned.

Sample Input:
241

Sample Output:
11110001

No Comments

Sorry, the comment form is closed at this time.