Question

create a basic python program that converts binary to number (using if statements etc) Asking user...

create a basic python program that converts binary to number (using if statements etc)

Asking user for input of binary number

converting/calculating

printing

Homework Answers

Answer #1

1ST PROCESS - ESY CODING FOR UNDERSTANDING

n = input("enter value in binary number to convert into integer:")

# Convert n to base 2
s = int(n, 2)

print(s)

2ND PROCESS ACCORDING TO QUESTION:-


                                                        

def binaryToDecimal(n):
    num = n;
    dec_value = 0;
   
    # Initializing base
    # value to 1, i.e 2 ^ 0
    base1 = 1;
   
    len1 = len(num);
    for i in range(len1 - 1, -1, -1):
        if (num[i] == '1'):   
            dec_value += base1;
        base1 = base1 * 2;
   
    return dec_value;

num = input("enter value in binary number to convert into integer:")
print(binaryToDecimal(num));
  


                             PLEASE RATE

Know the answer?
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
Similar Questions
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for 5 bases and 5 heights (you can use an array), have a function to print the triangle bases, heights, and areas 2. Create a structure for the Triangle that holds the base and height of the triangles. Ask the user for 5 triangles, and print them. 3. Create an array of 5 structures - ask the user for 5 triangles, and then print the...
Write a program in python to display all the consonant in the user input. E.g. user...
Write a program in python to display all the consonant in the user input. E.g. user input: Hello Good Day to you. Output: consonant H = 1 consonant l = 2 consonant G = 1   consonant d = 1 consonant D = 1 etc
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
c program with notes Start by asking the user to enter a number between 100 and...
c program with notes Start by asking the user to enter a number between 100 and 10,000. Check if the user has complied. Keep asking the user for a number between 100 and 10,000 until the user complies.Then print on the screen the digits of that number in reverse order
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
In Python You must create a flowchart, and its corresponding Python program, to solve the following...
In Python You must create a flowchart, and its corresponding Python program, to solve the following problem: 1. Using a repetition structure, evaluate the factorial of a positive whole number n: n! = n · (n - 1) · (n - 2) · ... · 1, where n >=1 Your program must take into account the cases in which the user enters an incorrect number and provide an error message for such cases.
- Write a Python program which asks the user to enter a number, if the number...
- Write a Python program which asks the user to enter a number, if the number is divisible by 6 or 7, the program prints “The number X is divisible by 6 or 7” and if the number is neither divisible by 6 nor by 7, then it prints “The number X is not divisible by 6 and 7”.
VISUAL BASIC FOR APPLICATIONS PLEASE! Create an application that lets the user enter a number of...
VISUAL BASIC FOR APPLICATIONS PLEASE! Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
Write a Python program that plays a number guessing game with a human user. The human...
Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT