I am using Python 3.7 and I have some questions about my code.
what does "returning the string only" mean? If a function is just returning the string, how can I print that - returned string at the end of my code?
For example, if I write the following code:
def word(num):
d1= {0:'Zero',1:'One',2:'Two',3:'Three',4:'Four',5:'Five',6:'Six',7:'Seven',8:'Eight',9:'Nine',10:'Ten',11:'Eleven',12:'Twelve',13:'Thirteen',14:'Fourteen',15:'Fifteen',16:'Sixteen',17:'Seventeen',18:'Eighteen',19:'Ninteen',20:'Twenty',30:'Thirty',40:'Fourty',50:'Fifty',60:'Sixty',70:'Seventy',80:'Eighty',90:'Ninty'}
if num >= 100 or num <= -100:
return "This number is out of range"
elif num < 0:
return "This number is less than 0 and it's spelling is Minus " + word(-num)
elif num < 20:
return d1[num]
else:
if num % 10 == 0:
return d1[num]
else:
return d1[num
print (word(- 100))
print (word(- 42))
print (word(13))
Here the function is printing as well. But if I want to return the string from this function and want to print the returned string outside of this function, how can I do that?
The way I tried, is it right?
What I have tried:
def main():
print (word(-100))
print(word(-42))
print(word(13))