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
When forced distribution is used to reduce leniency bias, this can cause __________ if a pfp system is in place?
ziro4ka [17]
When forced distribution is used to reduce leniency bias, this can cause <decreased trust> between employees if a pfp system is in place.
3 0
3 years ago
When you add encryption to a powerpoint presentation what does it do
abruzzese [7]

Answer: your document will be inaccessible

5 0
2 years ago
Average of Grades - Write a program that stores the following values in five different variables: 98, 87, 84, 100, 94. The progr
liubo4ka [24]

Answer:

Not sure what language, but in python a super basic version would be:

val1 = 98

val2 = 87

val3 = 84

val4 = 100

val5 = 94

sum = val1 + val2 + val3 + val4 + val5

avg = sum / 5

print(avg)

Explanation:

4 0
3 years ago
Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with
Nikolay [14]

Answer:

/******************************************************************************

                             Online C++ Compiler.

              Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

bool equal(int sys[],int user[])

{

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

{

 if(sys[i]!=user[i]){

     return false;

 }

}

return true;

}

int main()

{

int sys[7];

int user[7];

int min=0

;int max=9;

string userinput;

while(0==0){

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

{

    sys[i]=rand() % (max - min + 1) + min;

}

cout <<endl;

   cout<<"enter numbers"<<endl;

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

{

 getline (cin,userinput);

    if(userinput=="x"){

        return 0;

    }

    else{

 stringstream(userinput) >> user[i];

   

    }

}

     cout<<"User number"<<endl;

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

{

    cout << user[i];

}

    cout<<"system number"<<endl;

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

{

    cout << sys[i];

}

if(equal(sys,user))

{

   cout<<"You won !"<<endl;

}else {

       cout<<"Try again :("<<endl;

}

}

   return 0;

}

Explanation:

Using c++ rand function generate a random number between 0-9.

Formula for random number is rand (max-min +1)+min.

Run this in a loop for 7 time and store each number to an array index in sys array which is for system generated number.

now using string take input from user and check if input is x close program else use stringstream to parse input string to int and store it in user array. Stringstream is a cpp header file used for parsing and handling of strin g inputs. Run this program in loop for 7 times.

Now create a function of type boolean denoted by "bool". This will take both arr as parameter and check if both are equal or not. It compares eac index of user array against each index of sys array and if both values are not equal returns false.

5 0
3 years ago
Which of the following is a sign that a website is inappropriate?
nata0808 [166]

Answer:

A

Explanation:

If you find something embarrassing, its more likely that other people with also think its embarrassing. All the other points are on the internet right now. Amazon sells things, News show information and there are political campaigns to show you there offers

3 0
3 years ago
Read 2 more answers
Other questions:
  • Hope wants to add a third use at the end of her
    14·1 answer
  • How long does it take to wire a house?
    14·2 answers
  • A_____refers to the entire Excel file
    14·1 answer
  • A(n) monitoring vulnerability scanner is one that listens in on the network and determines vulnerable versions of both server an
    7·1 answer
  • During the ________ phase of the systems development life cycle process, developers construct, install, and test the components
    13·1 answer
  • The computer program that Josh is working on presents him with a sentence in which a word has been underlined. Josh has to indic
    9·1 answer
  • Will give 5 star and the mark brainleist
    11·2 answers
  • Who is willam afton from five nights at freddy
    13·2 answers
  • Define Rule Of Thirds
    9·1 answer
  • Which of the following best explains how algorithms that run on a computer can be used to solve problems?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!