I want to be able to print symbols that represent numbers using functions and while loops
Ex:
number = 250
# symbols
C = 100
^ = 50
should print
CC^
While printing one function may work, trying to concatenate two or more print functions lead me to the type error:
TypeError: can't multiply sequence by non-int of type 'function'
number = 251;
def numeral_C(number_par):
while number_par >=100:
numeral_C = number_par / 100
print "C"*numeral_C,
number_par = number_par - numeral_C*100
return ""
def numeral_UpArrow(number_par):
while number_par >=50:
numeral_upArrow = number_par / 50
print "^"*numeral_UpArrow, #error
number_par = number_par - numeral_UpArrow*50
return ""
etruscan_C = str(numeral_C(number))
etruscan_UpArrow = str(numeral_UpArrow(number)) #error
print etruscan_C+etruscan_UpArrow
Traceback (most recent call last):
File "/Applications/Wing IDE/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 15, in
File "/Applications/Wing IDE/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 11, in numeral_UpArrow
**TypeError: can't multiply sequence by non-int of type 'function'
I wonder, Is there a way I can print two or more functions without getting the error?
As the others state, you have a problem in re-using in an assignment something that is already the same name as a function:
As you can see by the comments, a simple rename of your function will cure this, and perhaps even a rename of your variable. But onto what I consider the ‘larger’ problem…
I feel like your original math makes a needless loop. compare the behavior of your numeral_C with my numeral_c: both result in the same numeral-C, but one is more re-usable (by having the ‘C’ return as a string) and also it lacks a loop and lots of reassignments.
Realistically, I cannot find a case when the loop will happen a second time, based on your reassignment of number_par to subtract the nearest FLOORED 100-multiple. In other words, much of that logic is useless. You could reasonably accomplish that whole function with: