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
White raven [17]
3 years ago
12

Compute the average of a list of user-entered integers representing rolls of two dice. The list ends when 0 is entered. Integers

must be in the range 2 to 12 (inclusive); integers outside the range don't contribute to the average. Output the average, and the number of valid and invalid integers (excluding the ending 0). If only 0 is entered, output 0. The output may be a floating-point value.Ex: If the user enters 8 12 13 0, the output is:Average: 10Valid: 2Invalid: 1Hints:
Computers and Technology
1 answer:
Leno4ka [110]3 years ago
6 0

Answer:

mylist = []

total = 0

valid = 0

invalid = 0

num = int(input("Number: "))

while num != 0:

    mylist.append(num)

    if(num>=2 and num<=12):

         total = total + num

         valid = valid + 1

    else:

         invalid = invalid + 1

    num = int(input("Number: "))

   

print("Average: "+str(total/valid))

print("Valid: "+str(valid))

print("Invalid: "+str(invalid))

   

Explanation:

The solution is implemented in Python

This line defines an empty list

mylist = []

The next three lines initializes total, valid input and input to 0 respectively

total = 0

valid = 0

invalid = 0

This line prompts user for input

num = int(input("Number: "))

This loop is repeated while input number is not 0

while num != 0:

This adds input number to the list

    mylist.append(num)

This checks for valid inputs

    if(num>=2 and num<=12):

If valid, the sum is calculated

<em>          total = total + num</em>

And the number of valid inputs is incremented by 1

<em>          valid = valid + 1</em>

If otherwise,

    else:

The number of invalid inputs is incremented by 1

         invalid = invalid + 1

This prompts user for another input

    num = int(input("Number: "))

   

This calculates and prints the average

print("Average: "+str(total/valid))

This prints the number of valid inputs

print("Valid: "+str(valid))

This prints the number of invalid inputs

print("Invalid: "+str(invalid))

You might be interested in
Media messages are communicated through which of the following:
LenaWriter [7]
All of the above is the answer
3 0
4 years ago
Read 2 more answers
A hemi combustion chamber shape can be found on _______ design engines.
miv72 [106K]
The combustion chamber heats high pressure air that is fed by the compression system into the compression system at constant pressure. <span>A </span>hemispherical combustion chamber<span> is a type of </span>combustion chamber with hemispherical design. <span>A hemi combustion chamber shape can be found on only overhead camshaft (OHC) design engines. </span>
8 0
4 years ago
In cell M2, enter a formula using a nested IF function as follows to determine first if a student has already been elected to of
aleksley [76]

Answer:

Following are the code to this question:

code:

=IF(EXACT(I2,"Yes"),"Elected",IF(EXACT(K2,"Yes"),"Yes","No"))

Explanation:

In the given the data is not defined so we explain only  the above code, but before that, we briefly define working of if the function that can be defined as follows:

  • The If() function, is used only when one of the logical functions and its value must return the value true. or we can say it only return a true value.
  • In the above function, a column "Elected" is used that uses other column values to check this column value is equal if this condition is true it will return "yes" value.

8 0
3 years ago
A .jpg file is an example is an example of which if the following file types
Setler79 [48]
Answer chooses would help but a .jpg is a picture
4 0
3 years ago
Write a program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name wil
sergeinik [125]

Answer:

// program in Python

# function to find grade

def grade(t_score):

   #grade A

   if t_score >=90:

       return 'A'

       #grade B

   elif t_score >=80 and t_score <90:

       return 'B'

   #grade C

   elif t_score >=70 and t_score <80:

       return 'C'

   #grade D

   elif t_score >=60 and t_score <70:

       return 'D'

   #grade F

   else:

       return 'F'

# function to find average score

def calc_average(test_score):

   #variable to find sum

   total = 0

   for i in range(len(test_score)):

       #calculate total score

       total = total + test_score[i]

   # find average

   return total/float(len(test_score))

#array to store score

test_score = []

#read name of student

name = input("Enter student's name: ")

for i in range(8):

   #read score

   t_score = int(input("Enter the score {}: ".format(i+1)))

   #add score to array

   test_score.append(t_score)

#call function to find Average

averageScore = calc_average(test_score)

#print name of Student

print("Student Name: ", name)

#print each Score

for i in range(len(test_score)):

   #print each Score and Grade

   print("Score: ",test_score[i], "Letter Grade: ",grade(test_score[i]))

# print Average Score

print("Average Score: ", averageScore)

Explanation:

Read name of student from user.Then read 8 test scores from user. Call the function grade() to find the grade of a test score.Call the function calc_average() to  find the average score of all test.Print each score and corresponding grade and print  average score.

Output:

Enter student's name: Sam                                                                                                  

Enter the score 1: 45                                                                                                      

Enter the score 2: 98                                                                                                      

Enter the score 3: 67                                                                                                      

Enter the score 4: 86                                                                                                      

Enter the score 5: 60                                                                                                      

Enter the score 6: 77                                                                                                      

Enter the score 7: 92                                                                                                      

Enter the score 8: 32                                                                                                      

Student Name:  Sam                                                                                                        

Score:  45 Letter Grade:  F                                                                                                

Score:  98 Letter Grade:  A                                                                                                

Score:  67 Letter Grade:  D                                                                                                

Score:  86 Letter Grade:  B                                                                                                

Score:  60 Letter Grade:  D                                                                                                

Score:  77 Letter Grade:  C                                                                                                

Score:  92 Letter Grade:  A                                                                                                

Score:  32 Letter Grade:  F                                                                                                

Average Score:  69.625  

3 0
3 years ago
Other questions:
  • This elementary problem begins to explore propagation delay and transmission delay, two central concepts in data networking. Con
    10·1 answer
  • I wanna learn coding, programming (to create my own websites, games, apps, etc)
    9·1 answer
  • What is best method for modern businesses to authorize the use of workplace resources to its employees
    7·2 answers
  • The following program contains 6 errors. Correct the errors and submit a working version of the program. The corrected version o
    13·1 answer
  • Mary needs to choose the _____ menu in order to place the text in a desirable fashion around the image
    12·2 answers
  • Write the simplest statement that prints the following on a single line: 3 2 1 Go! Note: Whitespace (blank spaces / blank lines)
    11·1 answer
  • Moving Images are called________.
    15·1 answer
  • Computer crimes are a big concern since the creation of innovative technological advances; which is/are examples of computer cri
    13·2 answers
  • How to follow accounts on brainy
    11·1 answer
  • Choose the response that best completes the following statement.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!