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
Setler79 [48]
3 years ago
12

Define a function below, sum_numeric_vals, which takes a single dictionary as a parameter. The dictionary has only strings for k

eys, but can have string or integer values. Complete the function to calculate and return the sum of the integer values in the dictionary.
Computers and Technology
1 answer:
notka56 [123]3 years ago
3 0

Answer:

Following are the program in the Python Programming language.

#define function

def sum_numeric_vals(dic):

 #set and initialize the integer variable to 0

 sum_total = 0

 #set the for loop to extract the value of dictionary

 for val in dic.values():

   #set if condition to find the sum

   if type(val)==int:

     sum_total += val

 #return the sum of the values

 return sum_total

#set and initialize dictionary type variable

dic={"Two":2,"Four":4}

#call and print the function

print(sum_numeric_vals(dic))

<u>Output:</u>

6

Explanation:

Here, we define the function "sum_numeric_vals()" and pass an argument "dic", inside the function.

  • Set and initialize an integer data type variable "sum_total" to 0.
  • Set the for loop which extract the values of the dictionary.
  • Set the if conditional statement inside the loop to find the sum of the values of the dictionary.
  • Then, return the sum of the values of the dictionary.

Finally, we set and initialize the dictionary type variable "dic" and pass it in the function's argument list then, call the function through the print function

You might be interested in
Create a new Die object. (Refer to Die.html for documentation.)Create a loop that will iterate at least 100 times. In the loop b
hjlf

Answer:

Java code is given below

Explanation:

import java.util.Random;

class Die{

private int sides;

public Die(){

sides = 6;

}

public Die(int s){

sides = s;

}

public int Roll(){

Random r = new Random();

return r.nextInt(6)+1;

}

}

class DieRoll{

public static void main(String[] args) {

Die die = new Die();

int arr[] = new int[6];

for(int i=0; i<6; i++)

arr[i] = 0;

for(int i=0; i<100; i++){

int r = die.Roll();

arr[r-1]++;

}

for(int i=0; i<6; i++)

System.out.println((i+1)+" was rolled "+arr[i]+" times.");

}

}

8 0
3 years ago
Help i need 76 more points to rank up can some one nice get me those? please please please
lutik1710 [3]
????????????????????????
6 0
2 years ago
Read 2 more answers
Why must programs written in a high-level language be translated into machine language?
eimsori [14]
The only thing that a computer actually understands is machine language. English-like constructs are gibberish to a computer, so they need to be translated by a compiler to machine language to run natively.
4 0
2 years ago
A batholith is an example of a(n) _____ igneous rock (one of the two main igneous rock groups).
Naily [24]
A batholith is an intrusive igneous rock.
3 0
3 years ago
Read 2 more answers
4. What is the package name in which the Scanner class resides?
Ahat [919]
Related Articles. Scanner is a class in java. util package used for obtaining the input of the primitive types like int, double, etc. and strings.
7 0
2 years ago
Other questions:
  • In Word, blue underlining indicates which of these problems?
    12·1 answer
  • What pressure will be shown on the high side peessure gauge (ac system on)
    12·1 answer
  • In which of the security mechanism does the file containing data of the users/user groups have inbuilt security?
    6·1 answer
  • Which is used to identify the network portion and the host portion of an ip address?
    6·1 answer
  • What type of engineer is interested in designing, developing, and building different machines, devices, and tools? A.aerospace
    8·2 answers
  • What is the difference between a try block and a try statement? Group of answer choices There is no difference; the terms can be
    6·1 answer
  • Hazel has just finished adding pictures to her holiday newsletter. She decides to crop an image. What is cropping an image?
    10·1 answer
  • Who here would like to play among us with me? <br> Time: Friday, November 13
    14·1 answer
  • What are your strongest competencies? What will you do them? <br>❌NONSENSE ANSWER<br>​
    9·1 answer
  • Lab 8-1: Working with Boot Loader and Runlevels what is the root password
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!