🌐
Reddit
reddit.com › r/learnpython › [please help!] 7.21 lab: convert to binary - functions
r/learnpython on Reddit: [Please HELP!] 7.21 LAB: Convert to binary - functions
May 4, 2023 -

Hello all!!

I would like to thank you for taking your time checking out this post.

I'm currently hard stuck and can't really tell why my code is not working properly :(

Instruction

Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:

As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x // 2 

Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.

Ex: If the input is:

6 

the output is:

110 

The program must define and call the following two functions. Define a function named int_to_reverse_binary() that takes an integer as a parameter and returns a string of 1's and 0's representing the integer in binary (in reverse). Define a function named string_reverse() that takes an input string as a parameter and returns a string representing the input string in reverse.

def int_to_reverse_binary(integer_value)

def string_reverse(input_string)

==============================================================================

This is my code so far

# Define your functions here.
def int_to_reverse_binary(integer_value):
    integer_value = int(integer_value)
    while integer_value > 0:
        print(integer_value % 2,end="")
        integer_value = integer_value // 2
    return str(integer_value)
    
    
def string_reverse(input_string):
    return str(input_string)[::-1]
    

if __name__ == '__main__':
    x = input()
    y = int_to_reverse_binary(x)
    print(string_reverse(y),end="")

I was expecting to get an output of "110" with a "6" as an input, but I'm keep getting 0110.

Program output displayed here

0110

Can anyone explain why I'm getting an additional "0" in the front? I would like to know why this is not working and may be a suggestion! Thank you in advance!

Hex to Binary problem May 7, 2021
r/learnpython
5y ago
Can somebody help me solve these binary problems?? Nov 18, 2021
r/learnprogramming
4y ago
Unexpected result trying to convert hex to binary Oct 5, 2021
r/learnpython
5y ago
Converting Integers to Binary--Question! Feb 19, 2013
r/java
13y ago
ELI5: Converting to and from binary Aug 4, 2014
r/explainlikeimfive
12y ago
More results from reddit.com
People also ask

24 LAB: Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string. Ex: If the input is: 6 the output is: 110 Your program must define and call the following two functions. The function integer_to_reverse_binary() should return a string of 1's and 0's representing the integer in binary (in reverse). The function reverse_string() should return a string representing the input string in reverse. def integer_to_reverse_binary(integer_value) def reverse_string(input_string) Use Python, please.
Algorithm: According to the algorithm mentioned, function integer_to_reverse_binary is written and…
🌐
bartleby.com
bartleby.com › bartleby textbook solutions › engineering q&a and textbook solutions › computer science q&a, textbooks, and solutions › computer science q&a library › 6.24 lab: convert to binary - functions write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. for an integer x, the algorithm is: as long as x is greater than 0 output x % 2 (remainder is either 0 or 1) x = x // 2 note: the above algorithm outputs the 0's and 1's in reverse order. you will need to write a second function to reverse the string. ex: if the input is: 6 the output is: 110 your program must define and call the following two functions. the function integer_to_reverse_binary() should return a string of 1's and 0's representing the integer in binary (in reverse). the function reverse_string() should return a string representing the input string in reverse. def integer_to_reverse_binary(integer_value) def reverse_string(input_string) use python, please.
Answered: 6.24 LAB: Convert to binary - functions Write a program ...
🌐
Stack Overflow
stackoverflow.com › questions › 72709391 › convert-integer-to-binary-using-2-functions-python
Convert integer to binary using 2 functions - Python - Stack Overflow
For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order.
🌐
Course Hero
coursehero.com › mustafa kemal university - tayfur sökmen campus › cs › cs misc
Convert to Binary: Write a Program to Convert Positive Integers | Course Hero
April 26, 2023 - 6.21 LAB: Convert to binary - functions Write a program that takes in a positive integer asinput, and outputs a string of 1 's and 0 's representing the integer in binary. For an integer x, thealgorithm is: AElongasxisgreaterthan0Outputx&2i...
🌐
Reddit
reddit.com › r/learnpython › convert to binary - functions
r/learnpython on Reddit: Convert to binary - functions
April 25, 2022 -

I've messed with this a couple of different ways. Can't seem to piece it together.

Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:

As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x // 2 

Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.

Ex: If the input is:

6 

the output is:

110 

The program must define and call the following two functions. Define a function named int_to_reverse_binary() that takes an integer as a parameter and returns a string of 1's and 0's representing the integer in binary (in reverse). Define a function named string_reverse() that takes an input string as a parameter and returns a string representing the input string in reverse.
def int_to_reverse_binary(integer_value)
def string_reverse(input_string)

def int_to_reverse_binary(integer_value):
    num = ''
    for i in len(str(integer_value)):
        num += integer_value % 2
        num //= 2
        return num
        
def string_reverse(input_string):
    int_to_reverse_binary(integer_value)
    reverse_num = num
    return reverse_num[::-1]

if __name__ == '__main__':
    # Type your code here. 
    # Your code must call int_to_reverse_binary() to get 
    # the binary string of an integer in a reverse order.
    # Then call string_reverse() to reverse the string
    # returned from int_to_reverse_binary().
    integer_value = int(input())
    
    print(int_to_reverse_binary(integer_value))
    #print(string_reverse(int_to_reverse_binary(integer_value)))
🌐
Bartleby
bartleby.com › bartleby textbook solutions › engineering q&a and textbook solutions › computer science q&a, textbooks, and solutions › computer science q&a library › 6.24 lab: convert to binary - functions write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. for an integer x, the algorithm is: as long as x is greater than 0 output x % 2 (remainder is either 0 or 1) x = x // 2 note: the above algorithm outputs the 0's and 1's in reverse order. you will need to write a second function to reverse the string. ex: if the input is: 6 the output is: 110 your program must define and call the following two functions. the function integer_to_reverse_binary() should return a string of 1's and 0's representing the integer in binary (in reverse). the function reverse_string() should return a string representing the input string in reverse. def integer_to_reverse_binary(integer_value) def reverse_string(input_string) use python, please.
Answered: 6.24 LAB: Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer… | bartleby
October 29, 2021 - 6.24 LAB: Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 ...
🌐
Bartleby
bartleby.com › bartleby textbook solutions › engineering q&a and textbook solutions › computer science q&a, textbooks, and solutions › computer science q&a library › :convert to binary - functions
Answered: :Convert to binary - functions | bartleby
October 31, 2021 - The function reverse_string() should return a string representing the input string in reverse. def integer_to_reverse_binary(integer_value) def reverse_string(input_string)
Find elsewhere
🌐
Brainly
brainly.com › computers and technology › college › 6.24 lab: convert to binary - functions write a program that takes in a positive integer as input and outputs a string of 1's and 0's representing the integer in binary. for an integer \(x\), the algorithm is: as long as \(x\) is greater than 0: 1. output \(x \% 2\) (remainder is either 0 or 1) 2. \(x = x // 2\) note: the above algorithm outputs the 0's and 1's in reverse order. you will need to write a second function to reverse the string. example: if the input is: \[6\] the output is: \[110\] the program must define and call the following two functions: 1. define a function named `int_to_reverse_binary()` that takes an integer as a parameter and returns a string of 1's and 0's representing the integer in binary (in reverse). 2. define a function named `string_reverse()` that takes an input string as a parameter and returns a string representing the input string in reverse. ```python def int_to_reverse_binary(integer_value): # your code here def string_reverse(input_string): # your code here ``` the functions should be implemented in python.
[FREE] 6.24 LAB: Convert to binary - functions Write a program that takes in a positive integer as input and - brainly.com
July 16, 2022 - To convert a positive integer to binary in Python, define two functions: one to generate the binary representation in reverse and another to reverse the string. The output can be tested with a sample integer like 6, resulting in the correct ...
🌐
Course Hero
coursehero.com › kean university › cis › cis misc
Convert Positive Integers to Binary with Python Functions | Course Hero
April 18, 2023 - You will need to write a second function toreverse the string. Ex: If the input is: 6 the output is: 110 The program must define and call thefollowing two functions. Define a function named int_to_reverse_binary0 that takes an integer as
🌐
Brainly
brainly.com › engineering › college › 6.27 lab: convert to binary - functions write a program that takes in a positive integer as input and outputs a string of 1's and 0's representing the integer in binary. for an integer \( x \), the algorithm is:
[FREE] 6.27 LAB: Convert to Binary - Functions Write a program that takes in a positive integer as input and - brainly.com
February 21, 2020 - For an integer x, the algorithm is:As long as x is greater than 0 Output x modulo 2 (remainder is either 0 or 1) Assign x with x divided by 2Note: The above algorithm outputs the 0's and 1's in reverse order.Ex: If the input is:6the output is:0116 ...
🌐
YouTube
youtube.com › richard halverson
ITS128 Video 19 Fall 2021 Chapter Sections 6.21 - 6.25 - YouTube
ITS128 Video 19 Fall 2021 Chapter Sections 6.21 - 6.25
Published: October 30, 2021
Views: 1K
🌐
Bartleby
bartleby.com › bartleby textbook solutions › engineering q&a and textbook solutions › computer science q&a, textbooks, and solutions › computer science q&a library › lab 6.24.1: lab: convert to binary- functions activity main.py 1 # define your function here. 2 3 if '_main_': name 4 # type your code here. your code must call the function.
Answered: LAB 6.24.1: LAB: Convert to binary-… | bartleby
November 1, 2021 - Ex: If the input is: the output is: 110 Your program must define and call the following two functions. The function integer_to_reverse_binary0 should return a string of 1's and 's representing the integer in binary (in reverse). The function reverse_string() should return a string representing ...
🌐
Course Hero
coursehero.com › arizona state university › cse › cse python
6.24 LAB: Convert to binary - functions .py - def int to reverse binary num1 : rev bin = while num1!=0: rev bin = str num1%2 num1 = num1/2 return | Course Hero
October 1, 2022 - rev = ch + revreturn revif __name__ == '__main__':num = int(input())rev_bin = int_to_reverse_binary(num)bin = string_reverse(rev_bin)print(bin)
🌐
YouTube
youtube.com › watch
C Lab: Convert To Binary (Reverse)
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
GitHub
github.com › ryanhoang15 › Python
GitHub - ryanhoang15/Python: Python coding labs
Python coding labs. Contribute to ryanhoang15/Python development by creating an account on GitHub.
Author: ryanhoang15