14,216,746 members
Rate this:
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:

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:

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
Patrice T 14-Dec-18 15:22pm

what error message ?

Rate this:

## 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