In: Computer Science
Define a function digits_stars(...) which receives as input one digit (that is, an integer number greater or equal than 0 and less or equal than 9). The function should return a string. The string will have , alternating, a digit and a "*" symbol, starting with the digit 0, then a star, then the digit 1, then a star, and so on, alternating until reaching the input digit and one star symbol to end the string.
As an example, the following code fragment:
print (digits_stars(3))
should produce the output:
0*1*2*3*
***Follow the rules please, there is another useless answer about the same question in Chegg.
The answer to this question is as follows:
The code is as follows:
def digits_stars(digit):
result=''
if(digit>=0 and digit<=9):
#checking whether the digit is greater than or equal to 0
#checking whether the digit is less than or equal to 9
for i in range(digit+1):
#For each value upto the range concat the i and * to s
result=result+str(i)+"*"
return result
else:
print("Invalid input")
print(digits_stars(3))
Note:careful with indendations
The input and output is as follows: