Close
Close

Take integer inputs from user until he/she presses q ( Ask to press q to quit after every integer input ). Print average and product of all numbers.

   dannynanda13

want the solution of above question?

  • count = 0 sum = 0 product = 1 user_input = None while user_input != 'q': user_input = int(input('Enter a number: ')) sum = sum + user_input product = product * user_input count = count + 1 print('Average:', sum/count) print('Product:', product)
    - Nahfid
  • Can I contact admin?? I'ts important. Regards.
    - Maximuslni
  • Where is admin? It is important. Regards.
    - Maximusqep
  • Can I contact admin?? It is about advertisement on your website. Regards.
    - Maximusjba
  • Can I contact Administration? It is about advertisement on your website. Thanks.
    - Maximuslni
  • Can I contact admin?? It is important. Thanks.
    - Maximusqep
  • Where is administration? I'ts important. Thanks.
    - Maximusjba
  • Can I contact Administration? I'ts important. Thanks.
    - Maximuslni
  • Where is administration? I'ts important. Regards.
    - Maximuslni
  • Can I contact Administration? I'ts important. Thanks.
    - Maximusqep
  • Can I contact admin?? It is about advertisement on your website. Regards.
    - Maximusjba
  • Can I contact admin?? It is about advertisement on your website. Thanks.
    - Maximuslni
  • Where is moderator?? It is about advertisement on your website. Thanks.
    - Maximusqep
  • Where is moderator?? It is important. Regards.
    - Maximusjba
  • Where is administration? It is about advertisement on your website. Regards.
    - Maximuslni
  • Can I contact admin?? It is important. Regards.
    - Maximusqep
  • Where is administration? It is important. Regards.
    - Maximusjba
  • Can I contact Administration? I'ts important. Thanks.
    - Maximuslni
  • Where is moderator?? I'ts important. Thanks.
    - Maximusqep
  • Can I contact Administration? I'ts important. Thanks.
    - Maximusjba
  • Can I contact Administration? I'ts important. Regards.
    - Maximuslni
  • Where is administration? I'ts important. Thanks.
    - Maximusjba
  • Can I contact Administration? I'ts important. Regards.
    - Maximuslni
  • Where is admin? It is about advertisement on your website. Thanks.
    - Maximusqep
  • Can I contact Administration? It is important. Regards.
    - Maximusjba
  • #include <iostream> using namespace std; int main() { string number; int n; int i=0, avg, sum=0,product=1; cout<<"Enter integers for quite enter q: "; cin>>number; while(number!="q"){ n=stoi(number); i++; sum+=n; product*=n; avg=sum/i; cout<<"Average = "<<avg<<endl; cout<<"Product = "<<product<<endl<<endl; cout<<"Enter another integers for quite enter q: "; cin>>number; } return 0; }
    - redmehsud
  • #include<iostream> using namespace std; int main(){ char c; int sum=0; int i=1; int prod=1; while(c != 'q'){ int n; cout<<"Enter the input : "; cin>>n; sum = (sum+n)/i; i++; prod *= n; cout<<"Enter the q to quit and continue c :"; cin>>c; if(c=='q'){ break; } } cout<<"Average is : "<<sum<<endl; cout<<"Product is :"<<prod<<endl; return 0; }
    - SHIVAM KUMAR
  • Error 523 <a href=https://support.cloudflare.com/hc/en-us/articles/115003011431-Troubleshooting-Cloudflare-5XX-errors#523error>origin is unreachable</a>
    - Oduvan4ikBaip
  • Оттеночный гель для бровей https://maketoup.ru/category/sredstva-dlya-makiyazha-brovey/label-geli-and-ottenochnyie/ придает бровям красивую форму и насыщенный цвет. Пигменты натуральных оттенков идеально подойдут для любого цвета бровей.
    - ChristineBaip
  • Для этого следует удалить лишние волоски и подрезать кончики остальных. Wet n Wild Подводка-фломастер Proline Felt Ti.
    - Muttywex

Answers

  •   
    summ = 0
    count = 1
    while raw_input("Enter q to quit or any other key to continue") != 'q':
        summ = summ+input()
        count=count+1
    print summ/(count*1.0)
    

     


    • i have done this way, is it right? from random import randint a = 1 b = 6 g = 'c' while g=='c': num_1= int(randint(a,b)) num_2= int(randint(a,b)) num_3= int(randint(a,b)) num_4= int(randint(a,b)) num_5= int(randint(a,b)) num_6= int(randint(a,b)) num_7= int(randint(a,b)) num_8= int(randint(a,b)) num_9= int(randint(a,b)) num_10= int(randint(a,b)) summ= num_1+num_2+num_3+num_4+num_5+num_6+num_7+num_8+num_9+num_10 average= summ/10 product= num_1*num_2*num_3*num_4*num_5*num_6*num_7*num_8*num_9*num_10 print num_1 print num_2 print num_3 print num_4 print num_5 print num_6 print num_7 print num_8 print num_9 print num_10 print 'average is',average print 'product is',product g='q' if g=='q': break
      - dannynanda13
    • or this one is correct? from random import randint a=1 b=6 g='c' while g=='c': num_1= int(randint(a,b)) print num_1 g='q' if g=='q': break g='c' while g=='c': num_2= int(randint(a,b)) print num_2 g='q' if g=='q': break g='c' while g=='c': num_3= int(randint(a,b)) print num_3 g='q' if g=='q': break g='c' while g=='c': num_4= int(randint(a,b)) print num_4 g='q' if g=='q': break g='c' while g=='c': num_5= int(randint(a,b)) print num_5 g='q' if g=='q': break summ= num_1+num_2+num_3+num_4+num_5 average= summ/5.0 product= num_1*num_2*num_3*num_4*num_5 print 'average is',average print 'product is',product
      - dannynanda13
    • You are using random integer but the question asks to take input from user.
      - Amit Kumar
    • ok check this one, not using random int- g='c' while g=='c': a=input(1) print a g='q' if g=='q': break g='c' while g=='c': b=input(3) print b g='q' if g=='q': break g='c' while g=='c': c=input(4) print c g='q' if g=='q': break g='c' while g=='c': d=input(5) print d g='q' if g=='q': break g='c' while g=='c': e=input(8) print e g='q' if g=='q': break summ = a+b+c+d+e average = summ/5.0 product = a*b*c*d*e print 'average is',average print 'product is',product
      - dannynanda13
    • #include <iostream> using namespace std; int main() { string number; int n; int i=0, avg, sum=0,product=1; cout<<"Enter integers for quite enter q: "; cin>>number; while(number!="q"){ n=stoi(number); i++; sum+=n; product*=n; avg=sum/i; cout<<"Average = "<<avg<<endl; cout<<"Product = "<<product<<endl<<endl; cout<<"Enter another integers for quite enter q: "; cin>>number; } return 0; }
      - redmehsud

  •   
    import random
    # Some random Shenanigans
    # Ignore to Initialization for answer
    def comp_input():
        return comp_input(random.randchoice[random.randint(1, 100), random.randint(1, 100), ‘q’])
    
    
    
    # Initialization
    count = 0 
    sum = 0 
    product = 1 
    
    # Loop will run infinitely till user presses 'q'
    while True:
        # Uncomment user_input = comp_input, Comment user_input = input(...) for magic
        # user_input = comp_input
        user_input = input('Enter a number: ')
        if user_input == ‘q’: break
        user_input = int(user_input)
    
        # Store the result of addition of prev sum and user input
        sum = sum + user_input
            
        # Store the result of addition of prev sum and user input
        product = product * user_input
    
        # Count the number of times user gave integer input
        count = count + 1
    
    print('Average:', sum/count)
    print('Product:', product)

     


    • wanted to know this one is correct or not a.t.q- g='c' while g=='c': a=input(1) print a g='q' if g=='q': break g='c' while g=='c': b=input(3) print b g='q' if g=='q': break g='c' while g=='c': c=input(4) print c g='q' if g=='q': break g='c' while g=='c': d=input(5) print d g='q' if g=='q': break g='c' while g=='c': e=input(8) print e g='q' if g=='q': break summ = a+b+c+d+e average = summ/5.0 product = a*b*c*d*e print 'average is',average print 'product is',product
      - dannynanda13
    • a.t.q we were asked to press q after every integer input. if i go with your method then we will be able to take input only once before loop is broken. suppose i enter 5 before i give q. 5 will be added to sum and also multi with product. in this way av. and prod. will be printed. but problem is input is given only once. can't we give multiple inputs and break it step by step and then print their combined average and prod as i mentioned above. because acc. to yours input will be only once before the loop break otherwise it will run infinitely and we we will not come to conclusion.
      - dannynanda13

  •   
    more = "n"
    sum = 0
    False = "q"
    count = 0
    product = 1
    while more == "n":
        count = count +1
        x = float(raw_input("Enter Number"))
        sum = (sum + x)
        product = x*product
        print "Press q when you are done inputting the numbers or n to continue"
        more = raw_input("")  
    c = sum/count
    print "You Inputed", count, "Numbers"
    print "The Average of the Numbers is ", c
    print "The product of the numbers is ", product
    
    #Code written by Onasanya Tunde
    #fb.com/onasanyatunde on facebook
    

    http://fb.com/onasanyatunde



  •   

    print("Start entering numbers")
    sum=0
    c=0
    while 1:
        num=int(input())
        c=c+1
        sum=sum+num
        print("Press q when you are done inputting the numbers or y to continue")
        m=input()
        if m=='q':
            break
        
    print("Average",sum/c)
    print("Sum",sum)
     















  •   
    Hey guys,
    
    Check out the solution, please let me know if any correction in this program :)
    
    #Code 
    i=0
    a=100
    n=0
    while i <= a:
        print('Enter the input')
        user_input=str(input())
        if user_input!='q':
            n=n+int(user_input)
            print('Enter to continue or q to quit')
            i=i+1
        else:
            print('You have chosen to quit')
            break
    avg=n/i
    print("total time the user entered the value is : %d " %i)
    print("Average : %d" %avg)
    print("product of all the number : %d" %n)
    And the output will be like the below:

    Enter the input
    10
    Enter to continue or q to quit
    Enter the input
    10
    Enter to continue or q to quit
    Enter the input
    20
    Enter to continue or q to quit
    Enter the input
    q
    You have chosen to quit
    total time the user entered the value is : 3 
    Average : 13
    product of all the number : 40













     

    Thank you!!!

     



  •    SHIVAM KUMAR , GKV HARIDWAR

    #include using namespace std; 


    int main(){

    char c;

    int sum=0;

    int i=1;

    int prod=1,avg;

    while(c != 'q'){

    int n;

    cout<<"Enter the input : ";

    cin>>n;

    sum +=n; avg = sum /i;

    i++;

    prod *= n;

    cout<<"Enter the q to quit and continue c :";

    cin>>c;

    if(c=='q'){ break; }

    }  

    cout<<"Average is : "<<avg<<endl;

    cout<<"Product is : "<<prod<<endl;

    return 0;

    }





  •    khatarnaak1909

    using namespace std;

    #include int main(){

    int n,a,m;

    m=1;

    a=0;

    char b;

    for(int i=1;i>=1;i++) {

    cout << "enter a number"<<endl;

    cin>>n;

    m = m * n;

    a = a + n;

    cout << "to exit press q else n"<<endl;

    cin>> b;

    if (b =='q') {

    break; }

    else if (b =='n'){

    continue; }

    }

    cout<<"product is "<<m;

    cout<<"the sum is "<<a;

    return 0;

    }



  •    christabelselina

    Thanks for the very good answers that helped me gain new knowledge from this topic geometry dash lite 



  •    seoexpertim

    I realize this is one of the most meaningful counsel for me. And i am vivacious studying your article. however have to commentary upon some standard matters, the internet site style is unmodified; the articles are invincible. thank you for the ton of actual and viable explicit. Food Photography Denpasar Bali



  •    bilon83361

    IDM crack is a https://allpcworld.site/ program that modifies temporarily or permanently an application to eliminate limitations imposed on them originally. The crack version makes ... 



  •    willsaldana

    I find the information you give both interesting and helpful, so I read it often io games unblocked



Ask Yours
Post Yours
Write your answer