1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nadusha1986 [10]
3 years ago
12

In this problem, you will fill in the code for a function count_digits(val) that takes a positive integer, val, and returns a li

st containing the count of the number of times that each digit 0 - 9 appears in val. Type the provided code into IDLE (or whatever Python IDE you are using). You will fill in the code where specified in the count_digits function. The function contains the line of code count_lst
Computers and Technology
1 answer:
mars1129 [50]3 years ago
7 0

Answer:

def count_digits(val):

   count_lst = [0] * 10

   val = str(val)

   for digit in val:

       if digit == "0":

         count_lst[0] += 1

       elif digit == "1":

         count_lst[1] += 1

       elif digit == "2":

         count_lst[2] += 1

       elif digit == "3":

         count_lst[3] += 1

       elif digit == "4":

         count_lst[4] += 1

       elif digit == "5":

         count_lst[5] += 1

       elif digit == "6":

         count_lst[6] += 1

       elif digit == "7":

         count_lst[7] += 1

       elif digit == "8":

         count_lst[8] += 1

       elif digit == "9":

         count_lst[9] += 1

   return count_lst

Explanation:

Create a function called count_digits that takes one integer parameter, val

Initialize a count_list that will hold the counts for the digits in the val

Convert val to string

Initialize a for loop that iterates through the val

Inside the loop, check each digit in val and increment its corresponding position in the count_list

When the loop is done, return the count_list

You might be interested in
16. Budget Analysis Write a program that asks the user to enter the amount that he or she has budgeted for a month. A loop shoul
strojnjashka [21]

Answer:

import java.util.Scanner;

public class num8 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter month's budget");

       double monthBudget = in.nextDouble();

       double totalExpenses = 0.0;

       double n;

       do{

           System.out.println("Enter expenses Enter zero to stop");

           n = in.nextDouble();

           totalExpenses += n;

       }while(n>0);

       System.out.println("Total expenses is "+totalExpenses);

System.out.println("The amount over your budget is "+ Math.abs(monthBudget-totalExpenses));

   }

}

Explanation:

  • Using Java programming language
  • Prompt user for month's budget
  • Use Scanner class to receive and store the amount entered in a variable
  • Use a do while loop to continuously request user to enter amount of expenses
  • Use a variable totalExpenses to add up all the expenses inside the do while loop
  • Terminate the loop when user enters 0 as amount.
  • Subtract totalExpenses from monthBudget and display the difference as the amount over the budget

6 0
3 years ago
What are some differences between film and digital cameras?
inna [77]

The main difference is that digital cameras don't have film but they use memory cards instead, also while in film cameras the ligh sensitive part is the film, in digital cameras there is the CCD/CMOS sensor which captures the light and transforms it into a picture.

google


4 0
3 years ago
A Linux-based OS is called a _____.
solong [7]
It is called kernel
7 0
3 years ago
Write an Email of your Friend Asking Him Help i​
lyudmila [28]

Answer:

Explanation:

7

3 0
3 years ago
Read 2 more answers
Which type of boot authentciation is more secure?
xeze [42]
The correct answer would b (C) because all the other ones are not on the list
7 0
3 years ago
Other questions:
  • Match the spreadsheet features with their respective descriptions.
    9·2 answers
  • What is computer Network?​
    14·2 answers
  • What information should you avoid sharing when updating your status?
    14·2 answers
  • The _____ of each phrase in a melody can be drawn with a curved line that follows the direction of the note progression.
    15·1 answer
  • To use an imported image, simply drag it from the desktop onto the stage. true or false
    15·2 answers
  • Types of computer that we use in our daily life​
    13·2 answers
  • The year in which HTML was first proposed?
    14·2 answers
  • Define foreign key. What is this concept used for?
    6·1 answer
  • Why are Quick Parts useful in an Outlook message?
    10·2 answers
  • In a well-developed paragraph - using domain-specific vocabulary and academic writing - address the following writing prompt:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!