Undecimal to decimal&decimal to undecimal
#Your code here
Thank you!
def undecimal_to_decimal(undecimal_str):
decimal = 0
n = len(undecimal_str)
# Similar to decimal where we add powers of 10 multiplied with digit at position i,
# in undecimal we do it with 11.
# Power of 11 at position i in string is n-1-i (where n is length of string).
# So we need to do summation of digit(i) * (11 ^ (n-1-i)) where i is from 0 to n-1.
for i in range(n):
num = -1
if(undecimal_str[i] != "X"):
num = int(undecimal_str[i])
else:
num = 10
decimal += num*(pow(11,n-1-i))
return decimal
def decimal_to_undecimal(decimal):
undecimal_str = ""
# Similar to binary, to convert to undecimal, at each step we find the remainder of decimal with 11,
# add the remainder to the undecimal string and divide the decimal by 11.
# Doing this we get each digit of undecimal string.
while(decimal != 0):
rem = decimal % 11
decimal = decimal//11
if(rem == 10):
undecimal_str = "X" + undecimal_str
else:
undecimal_str = str(rem) + undecimal_str
return undecimal_str
Comments have been added for better understanding.
Please use the above functions in various scenarios to gain a better understanding of the code.
Please consider dropping an upvote to help out a struggling college kid :)
Happy Coding !!
Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we...
Convert a decimal fractional number 34/5 to its binary equivalent using a program to evaluate the bits of the fractional part for at least upto the second repeating block. i have written some code in python however it is not getting an output at all, so either fixing the code or writing another one would be beyond helpful def binary(n,k): n = 8.6 k = 3 #'n' is the fractional number #'k' is the number of bits up to the loop...
Python, given a code in class i just need help with the third bullet point ; using a and n (defined in the second picture of python code) find the first digit for k! for k =1,...,n. you dont have to type in all this code just help me write the code in the first picture where it says: def benford(a): b = [0 for d in range(1,10)] #Do everthything in here return b 2.2 Generating data In this assignment...
Use your Food class, utilities code, and sample data from Lab 1 to complete the following Tasks. def average_calories(foods): """ ------------------------------------------------------- Determines the average calories in a list of foods. foods is unchanged. Use: avg = average_calories(foods) ------------------------------------------------------- Parameters: foods - a list of Food objects (list of Food) Returns: avg - average calories in all Food objects of foods (int) ------------------------------------------------------- """ your code here is the...
for this code fix the smtax error this is a python code for some reason my code isnt liking my returns and it bring up other symtax error so fix the following code answer should pop out the following when runned 1/ 2 + 1/ 3 + 1/ 12 = 11/12 z=' ' def math(x,y): global z if y==0 or x==0: return if y%x ==0: z=("1/"+str(int(y/x)) return if x%y ==0 z+=(int(x/y)) ...
Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...
IN PYTHON ''' Helper func 3: checksum_ISBN Input: a list with 9 single digit number in it (first 9 digit in ISBN) Output: print out: "The correct checksum digit is:__. Now we have a legit ISBN: _____" Hint: just loop through 0-9, test every one with helper func1 to find out the one checksum that forms a legit ISBN with the correct ISBN in lis (10 numbers), call helper func2 to format it correctly. Then print the final result. '''...
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase: def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'): self.nameitem = nameitem self.item_prc = item_prc self.item_quntity = item_quntity self.item_descrp = item_descrp def print_itemvaluecost(self): string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc)) valuecost = self.item_quntity * self.item_prc return string, valuecost def print_itemdescription(self): string...
In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task. Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop int cnt = 1; do { cnt += 3; } while (cnt < 25); cout << cnt; It runs ________ times ...
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase: def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'): self.nameitem = nameitem self.item_prc = item_prc self.item_quntity = item_quntity self.item_descrp = item_descrp def print_itemvaluecost(self): string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc)) valuecost = self.item_quntity * self.item_prc return string, valuecost def print_itemdescription(self): string = '{}: {}'.format(self.nameitem, self.item_descrp) print(string , end='\n') return string class Shopping_Cart: #Parameter...
How do i finish this code: #include <stdio.h> int main() { long long decimal, tempDecimal, binary; int reminder, weight = 1; binary = 0.0; //Input decimal number from user printf("Enter any decimal number: "); scanf("%lld", &decimal); // Since we do not want change the value of decimal in the code // let us use tempDecimal to store the value of decimal tempDecimal = decimal; printf("\n\n"); // Let us use while loop first to implement printf("while loop part:\n"); /**************START FROM HERE...