Define function that convert number value to character digit

Assignment Help Python Programming
Reference no: EM131869920

Computer Science Number Systems Project Assignment

In this assignment you will add on to the source code from the Number Systems Lab in file "numberSystes.py". In the lab we defined a function for converting a character digit to its numeric value and laid out code that would simulate the Positional Notation method of converting numbers from any base to decimal. We will add to this the functionality to perform the Long Division method of converting a decimal to another base.

First take the code that you wrote that simulates Positional Notation and put it in a new function named "toDecimal". It will need to accept a character number and an integer base as parameters, and will return an integer decimal value.

Then define a function that can convert a number value to a character digit. For right now we will just assume we have valid values, so a zero through nine will convert to "0" through "9", and then a ten through fifteen will convert to "A" through "F".

Now create a function that simulates the long division method of converting a decimal to another base. It will need to receive an integer decimal value, and an integer base to convert it to, and will need to return a string value representing the converted value.

Remember that the long division method takes a decimal and divides it by the base to convert to. Each remainder of the division is the next digit in the result reading right to left. Each quotient from the division is used as the next dividend, until the quotient is zero.

A run of the program should prompt the user to enter a number, the base of the number, and the base to convert to the number to, and then print the results of converting the number to decimal, and then the decimal to the output base.

So a general process flow is:

  • Ask for number to convert
  • Ask for base of number
  • Ask for base to convert to
  • Set decimal to return of "toDecimal" passing the number-in and base-in
  • Print message number-in base base-in is decimal decimal-value
  • Set number-out to return of "fromDecimal" passing decimal and base-out
  • Print message decimal is number-out in base base-out

Outline of the fromDecimal function:

  • Define a string number-out and initialize it to an empty string, i.e. '' or "" (this will allow us to concatenate digits to it in a loop)
  • Set a quotient variable to the decimal passed in
  • Create while loop that checks for quotient great than zero
  • Set a remainder variable to quotient mod base-out
  • Set next-digit to return of valueToDigit passing in the remainder
  • Set a new-quotient variable to quotient integer-division base-out
  • Print this loop as: quotient / base-out = new-quotient , next-digit
  • Append next digit to front of number-out (e.g. sNumberOut = nextDigit + sNumberOut)
  • Set quotient to new-quotient
  • (Loop will continue till quotient is zero)
  • Return number-out

Attachment:- Assignment Files.rar

Reference no: EM131869920

Questions Cloud

Recommend two other practices which could be employed : Recommend at least two other practices which could be employed to encourage ethical behavior of TSA employees. Justify your response.
JQH returns are normally distributed : Assume that JQH’s returns are normally distributed. What is the probability of a return below 15%?
Determining the biostatistical methods : A college lecturer said ‘For the course "Biostatistical Methods", the percentage a student gets for the closed-book exam has always been fairly similar
Summarize the basic issues of government governance : There are certain important differences between developed and developing countries, some of which may lead to difficult ethical problems.
Define function that convert number value to character digit : COP 1500 Intro Computer Science Number Systems Project Assignment - Then define a function that can convert a number value to a character digit
Carefully on all aspects of statement : An environmental scientist said ‘I did a small pilot experiment with two replicates in each treatment and got the result we hoped for.
Compute the interest on loan : Compute the interest on a 15-year loan for $15023 if the annual rate is 4.9% with continuous compounding.
Result of a statistical test : 1.Why would many scientists be uneasy about a probability of 0.06 for the result of a statistical test?
Population of the snail calcarus porosis : It is known that a population of the snail Calcarus porosis on Kangaroo Island, South Australia, has a mean shell length of 100 mm and a standard deviation.

Reviews

len1869920

2/19/2018 11:55:50 PM

Python assignment, I need to add the fromDecimal function to my python code (attached) outlined in the word document (attached). Remember that the long division method takes a decimal and divides it by the base to convert to. Each remainder of the division is the next digit in the result reading right to left. Each quotient from the division is used as the next dividend, until the quotient is zero.

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd