208k views
5 votes
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)

User Sabari
by
9.3k points

2 Answers

2 votes

Final answer:

To reverse an integer in binary (in reverse order), use the bin() function, and for reversing a string, use string slicing with a step of -1.

Step-by-step explanation:

To define the function int_to_reverse_binary(), you can use the bin() function in Python to convert the integer parameter to a binary string. Then, you can slice the string to reverse it. Here's an example:

def int_to_reverse_binary(value):
binary_str = bin(value)[2:] # Remove '0b' prefix
reversed_str = binary_str[::-1]
return reversed_str

To define the function reverse_string(), you can use string slicing with a step of -1 to reverse the input string. Here's an example:

def reverse_string(input_str):
reversed_str = input_str[::-1]
return reversed_str
User Xiaoyu Lu
by
7.8k points
4 votes

In this program, the int_to_reverse_binary function takes an integer as input, converts it to a binary representation, removes the '0b' prefix, and then reverses the string.

def int_to_reverse_binary(integer_value):

# Convert integer to binary and reverse the string representation

binary_representation = bin(integer_value)[2:][::-1]

return binary_representation

def string_reverse(input_string):

# Reverse the input string

reversed_string = input_string[::-1]

return reversed_string

# Example usage:

# You can replace the values in the function calls with the ones you want to test

integer_value = 10

input_string = "Hello, World!"

User TommyTh
by
8.6k points