Question

Language is Python Question 1: Octoquadragesimal Conversion (6 points) There are many exotic base systems in the world, one of which is Octoquad

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def Octoquadragesimal2Binary(s):
res=0
for i in range(len(s)-1,-1,-1):
res+=(int(s[i]))*(48**(len(s)-1-i)) if s[i]>='0' and s[i]<='9' else (ord(s[i])-97+10)*(48**(len(s)-1-i)) if s[i]>='a' and s[i]<='z' else (ord(s[i])-65+36)*(48**(len(s)-1-i))
return '' if s.strip()=='' else bin(res)[2:]

def Binary2Octoquadragesimal(s):
if s.strip()=='':return ''
res=int(s,2)
toret=''
while res!=0:
rem=res%48
res=res//48
toret=(str(rem) if rem>=0 and rem<=9 else chr(rem+97-10) if rem>=10 and rem<=36 else chr(rem+65-36))+toret
return toret

Octoquadragesimal2Binary("Hamster")
Binary2Octoquadragesimal('111101100010010000001100100011110111011')

print(Octoquadragesimal2Binary("1md32020") == "1100100000011100011001100110000001100000")
print(Binary2Octoquadragesimal("1100100000011100011001100110000001100000") == "1md32020")

print(Octoquadragesimal2Binary("Dragonfly2026") == "1010000001101101011000000100000001000101111010000101101010110000001100110")
print(Binary2Octoquadragesimal("1010000001101101011000000100000001000101111010000101101010110000001100110") == "Dragonfly2026")

indentation reference:

In [44]: def Octoquadragesimal2Binary(s): res=0 for i in range(len(s)-1,-1,-1): res+=(int (s[i]))*(48**(len(s)-1-i)) if s[i]>

Sample i/o:

In [46] : Octoquadragesimal 2Binary(Hamster) Binary20ctoquadragesimal(111101100010010000001100100011110111011) print (OctExplanation:

The sample i/o, code and indentation reference is provided for your understanding and execution of the code. The code is executed in Jupiter notebook of python3 version.

**kindly upvote if you like the answer. Thank you

Add a comment
Know the answer?
Add Answer to:
Language is Python Question 1: Octoquadragesimal Conversion (6 points) There are many exotic base systems in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Programing : Convert to binary - functions Write a program that takes in a positive...

    Python Programing : 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...

  • LANGUAGE: PYTHON Write a function called: d_polybius(). The function applies the decryption scheme for the polybius...

    LANGUAGE: PYTHON Write a function called: d_polybius(). The function applies the decryption scheme for the polybius cipher scheme above. The start of the function call the get_polybius_square function to get the square as a string. The second scenario when the number of characters is not even, excluding ‘\n’. For instance: “71\n5” is an invalid cipher because there is no way that the last number correspond to a character (we need two numbers). A customized version of Polybius square will be...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...

  • In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of...

    In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of lists and functions with multiple inputs and multiple outputs. Your task is to implement the separate_and_sort function. This function takes two input parameters: 1. A list containing strings and integers in any order. 2. An optional integer parameter size which controls how many items in the list the function will process. If the length of the list is smaller than the value of size,...

  • This problem demonstrates the use of import module. The Python programming language has many strengths, but...

    This problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules. We have given you some incomplete code; note that the very first line of that code contains an import statement as follows: import math This statement enables your program to use a math...

  • can someone write me a wing101 python code for this please Question: For a projectile launched with a velocity vIm/s) at an angle to the horizontal 6 Iradl, the horizontal distance travelled (al...

    can someone write me a wing101 python code for this please Question: For a projectile launched with a velocity vIm/s) at an angle to the horizontal 6 Iradl, the horizontal distance travelled (also called the range) is given by where the altitude of the landing position is Δh higher than that of the launch position and g is the gravitational acceleration (use 9.81 m/s^2). Note: θ in theformula is in radians write a Python function that accepts ν, θ and...

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

  • C programming language Purpose The purpose of this assignment is to help you to practice working...

    C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT