i have write small python program converts 4 number binary input decimal equivalent of input. it's school assignment.
so stumbled upon while searching web help:
num_digits = 4 value = 0 err = false in range(num_digits): if i==0: n = int(input("enter leftmost digit: ")) else: n = int(input("enter next digit: ")) if n==0: pass elif n==1: power = (num_digits-1)-i value += (int) (pow(2, power)) else: err = true break if err: print ("error! incorrect binary number.") else: print ("the value is",value)
the above code works, don't understand why yet. part of assignment figure out how write such program ourselves.
so went ahead , wrote this:
value = 0 = int(input('geef eerste getal: ')) b = int(input('geef het volgende getal: ')) c = int(input('geef het volgende getal: ')) d = int(input('geef het volgende getal: ')) v = a+b+c+d print(int(v, 2)'het getal is: ')
i know there's wrong, not exactly. error when using int() string (like 'v' or 'value')
could explain me why happening? , maybe give me little breakdown of first program. understand what's behind larger code , how works.
thanks!
Comments
Post a Comment