Click here to Skip to main content
14,216,746 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying make a counter for base 4 numbers the base conversion is successful but when it comes to making a counter it gives me an error, can someone help?

What I have tried:

x=7
i=1
n=5
base=4
def toStr(n,base):
   convertString = "0123"
   if n < base:
      return convertString[n]
   else:
      return toStr(n//base,base) + convertString[n%base]
   return tostr(x//base,base)+convertstring[x%base]
   return tostr(i//base,base)+convertstring[i%base]

def counter(low, high):
    current = low
    while current <= high:
        yield current
        current += 1

for c in counter(toStr(n,base), toStr(x,base)):
    print(c)

print(toStr(n,base))
print(toStr(x,base))
print(toStr(i,base))



x=7
i=1
n=5
base=4
def toStr(n,base):
   convertString = "0123"
   if n < base:
      return convertString[n]
   else:
      return toStr(n//base,base) + convertString[n%base]
   return tostr(x//base,base)+convertstring[x%base]
   return tostr(i//base,base)+convertstring[i%base]

def counter(low, high):
    current = low
    while current <= high:
        yield current
        current += 1

for c in counter(toStr(n,base), toStr(x,base)):
    print(c)
Posted
Updated 14-Dec-18 9:47am
Comments
Patrice T 14-Dec-18 15:22pm
   
what error message ?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You're trying to loop over strings instead of numbers. What would you expect the result of "twelvety" + 1 to be? :)

Try:
for c in counter(n, x):
    print(toStr(c,base))
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100