Question

Octal numbers have a base of eight and the digits 0–7. Write the scripts octalToDecimal.py and...

Octal numbers have a base of eight and the digits 0–7. Write the scripts octalToDecimal.py and decimalToOctal.py, which convert numbers between the octal and decimal representations of integers. These scripts use algorithms that are similar to those of the binaryToDecimal and decimalToBinary scripts developed in the Section: Strings and Number Systems. An example of octalToDecimal.py input and output is shown below: Enter a string of octal digits: 234 The integer value is 156 An example of decimalToOctal.py input and output is shown below: Enter a decimal integer: 27 Quotient Remainder Octal 3 3 3 0 3 33 The octal representation is 33

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

octal ToDecimal.py # input ot n-int (input (Enter a string of octal digits: )) #required variables ds=0 #loop for conversion while (o t n l= 0): #t find remainder rma otn%10 ot n // 10 #print the results print (The integer value is , dc) output RESTART: C:\Users\admin\Desktopl octalToDecimal.py Enter a string of octal digits: 234 The integer value is 156 # decina!TOOctal.py

copyable code:

# octalToDecimal.py

#input

o_t_n=int(input('Enter a string of octal digits: '))

#required variables

i = 1

dc = 0

#loop for conversion

while (o_t_n != 0):

    #to find remainder

    rmd = o_t_n % 10

    o_t_n //= 10

    dc += rmd * i

    i *= 8

#print the results

print('The integer value is ',dc)

# decimalToOctal.py

#input

d_c_n=int(input('Enter a decimal integer: '))

print("Quotient Remainder Octal")

#required variables

i = 1

o_c_n = 0

num=""

#loop for conversion

while (d_c_n != 0):

    #to find remainder

    rm = d_c_n % 8

    d_c_n //= 8

    o_c_n = o_c_n + rm * i

    i *= 10

    num = str(rm)+num

    print("%5d%8d%12s" % (d_c_n, rm, num))

#print the results

print('The octal representation is ',o_c_n)

Add a comment
Know the answer?
Add Answer to:
Octal numbers have a base of eight and the digits 0–7. Write the scripts octalToDecimal.py and...
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
  • Description For this program, you are going to convert decimal (integer) numbers into their octal number...

    Description For this program, you are going to convert decimal (integer) numbers into their octal number (integer) equivalents. Make sure that you create a new Project and Java class file for this assignment. Your Repl.It file should be named “Main.java”. You can read about octal-to-decimal number conversions from wikepedia or another website Instructions The input to the program will be a single non-negative integer number. If the number is less than or equal to 2097151, convert the number to its...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • C++ program to convert between decimal, hexadecimal, and octal. Please Help!!

    Hi, I need help writing a program that reads in data (hex, octal or decimal values) from an input file and outputs the values in to another base form (hex, octal,decimal) one line at a time depending on the formatting characters provided by the input file. I am posting the code requirements below and an example of what theinput file will look like and what should be output by the program. I only need the one .cpp program file. Thanks...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Write an assembler program that asks the user (as shown below) for two integers and a...

    Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...

  • Design the logic circuit to display a 3 bit octal numbers from 0 to 7 on...

    Design the logic circuit to display a 3 bit octal numbers from 0 to 7 on a seven segment display shown below (for number 1 use segments b and c; for 6 include segment (a) Write the Truth Table with A, B. C representing the input bits (A is the MSB) and a, b, c, d, e, f and g representing the outputs to the seven segments. (b) Implement the circuit using a Programmable Logic Array (use simplified notation to...

  • Python Algorithm Coding There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.Yo...

    Python Algorithm Coding There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.You can create a continuous number by attaching the paper in a proper order. Print out the maximum number of digits sum of a sequence of numbers that can be made when N paper is given. For example, suppose you have a piece of paper with a lettering as shown below. In this case, the consecutive numbers of strings...

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

  • Python Script format please! 1. Write a script that takes in three integer numbers from the...

    Python Script format please! 1. Write a script that takes in three integer numbers from the user, calculates, and displays the sum, average, product, smallest, and largest of the numbers input. Important things to note: a. You cannot use the min() or max() functions, you must provide the logic yourself b. The calculated average must be displayed as an integer value (ex. If the sum of the three values is 7, the average displayed should be 2, not 2.3333). Example:...

  • Python Algorithm Coding There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.Yo...

    Python Algorithm Coding There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.You can create a continuous number by attaching the paper in a proper order. Print out the maximum number of digits sum of a sequence of numbers that can be made when N paper is given. For example, suppose you have a piece of paper with a lettering as shown below. In this case, the consecutive numbers of strings...

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