Question

please answer in pythonprint Cannot divide anything but numbers. else - print n. 5. (+15) Write a function bin2dec( ) that takes a string representa

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

import math
def bin2dec(binStr):
count=len(binStr);
decimalVal=0;
for i in range(0,count):
decimalVal=decimalVal+(int(binStr[count-i-1])*math.pow(2,i));
return decimalVal;
  
  
def main():
print(bin2dec('110'));
print(bin2dec('11111111'));
print(bin2dec('1'));
if __name__=="__main__":
main();

screenshot1 import math 2- def bin2dec(binStr): count=len(binStr); decimalval=0; for i in range(0,count): decimalval=decimalval+(int(bi

Expected output:

16.0 255.0 1.0

Add a comment
Know the answer?
Add Answer to:
please answer in python print Cannot divide anything but numbers. else - print n. 5. (+15)...
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
  • Can someone solve this practice exam question, python 3 5. (+15) Write a function bin 2dec...

    Can someone solve this practice exam question, python 3 5. (+15) Write a function bin 2dec ( ) that takes a string representation of any length binary number and returns the decimal equivalent without using any type conversions. Remember that the binary representation ofa number has a power of 2 in each position, starting with 2° in the right most position and increasing by 1 as it moves left (e.g. 222120) loina dec (nun det >>> bin2dec('110') 6 >>>bin2dec('11111111' )...

  • PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of...

    PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of positive integer numbers (a, b) such that c = a + b is also a whole number and 1 <c<n. Include only those triples that are co-prime (do not have any common divisors other than 1). For example, (3, 4, 5) is okay but (30, 40, 50) should be skipped. Help: As a starting example, examine the function pythagorian_triples that yields all triples. Modify...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each...

    please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available...

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