Question

In: Computer Science

Define a function digits_stars(...) which receives as input one digit (that is, an integer number greater...

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.

Solutions

Expert Solution

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:


Related Solutions

a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it...
a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. [2.5 marks] b. Write a c++ function, called GCD that receives two parameters n, d, and prints their greatest common divisor [2.5 marks] Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options...
Matlab program Create a function, when given a two-digit integer as input, prints the equivalent English...
Matlab program Create a function, when given a two-digit integer as input, prints the equivalent English phrase. For example, given 39, output thirty-nine. Limit the input numbers to be in the range 21 to 39.
Design and implement a function which has one input parameter which is a number which is...
Design and implement a function which has one input parameter which is a number which is greater than 50, called num. Then the function will create a dictionary whose keys are 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9. Then the function calculates the values for each of the above keys. The value for a key is all the numbers between 2 and input “num” that are divisible by the key. The function...
PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special...
PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special characters), possibly empty, and returns a new string containing the following. a) in those positions where the original string has an even digit, the corresponding character in the new (returned) string should have the string digit '0' b) in those positions where the original string has a vowel letter (upper or lower case), the new (returned) string should have the letter 'V'. Note that...
Write code in C please. #1 Write a function multiples() which will take an integer input...
Write code in C please. #1 Write a function multiples() which will take an integer input and it will print out all the multiples of this number starting from 2 but not including itself. For example, multiples(10) will print 2, 5 and multiples(100) will print 2, 4, 5, 10, 20, 25, 50 #2 Write and test a Fibonacci() function that uses a loop instead of recursion to calculate Fibonacci numbers.
C++ Only Create a function named PrintStudents, which takes a string input filename and an integer...
C++ Only Create a function named PrintStudents, which takes a string input filename and an integer minimum score value and a string output file name as a parameters. The function will read the student scores and names from the file and output the names of the students with scores greater than or equal to the value given. This function returns the integer number of entries read from the file. If the input file cannot be opened, return -1 and do...
In C language: Write a function which can receive a float array, an integer number(number of...
In C language: Write a function which can receive a float array, an integer number(number of elements) as input arguments and print all the elements in the array with 2 decimal precision.
Write a function which receives a list and returns a number. In the list, all numbers...
Write a function which receives a list and returns a number. In the list, all numbers have been repeated twice except one number that is repeated once. The function should return the number that is repeated once and return it.write a python program for this question. use main function.
//----------------------------------------------------------------- // Counts the number of odd, even, and zero digits in an integer // input...
//----------------------------------------------------------------- // Counts the number of odd, even, and zero digits in an integer // input value. Repeat as long as the user wishes to continue //----------------------------------------------------------------- public static void main(String[] args) {     // Declare the identifiers final int SENTINEL = -99;    // Declare the remaining identifiers ... Scanner scan = new Scanner(System.in);    // Display the programmer's information              // Input an integer number          // Count the number of odd, even, and...
A prime number is an integer greater than 1 that is evenlydivisible by only 1...
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided by 1, 2, 3, and 6.Write a Boolean function named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, and false otherwise. Demonstrate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT