Q. Write a short program to find average of list of number entered through keyboard.


You can understand by Watching video :-



Answer :-

sum = 0
feq = 0
while  True :
    a = input("Enter a number (for quit enter Yes )=  ")
    if a  ==  "Yes" or a == "yes" :
        print("average of numbers = ",sum/feq)
        break
    else :
        sum = sum + int(a)
        feq = feq + 1

Output :-

Enter a number (for quit enter Yes )=  8
Enter a number (for quit enter Yes )=  9
Enter a number (for quit enter Yes )=  10
Enter a number (for quit enter Yes )=  11
Enter a number (for quit enter Yes )=  yes
average of numbers =  9.5

>>> 

Enter a number (for quit enter Yes )=  5
Enter a number (for quit enter Yes )=  54
Enter a number (for quit enter Yes )=  789
Enter a number (for quit enter Yes )=  1234
Enter a number (for quit enter Yes )=  54425
Enter a number (for quit enter Yes )=  yes
average of numbers =  11301.4

>>>

27 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Maza ni aaya 😭😭😭😭😭😭

    ReplyDelete
  2. Thank you for the solutions

    ReplyDelete
  3. what is 'feq' referring over here(in the program)?

    ReplyDelete
    Replies
    1. It is counting the number of integer entered by user.

      Delete
  4. the program is showing error. is there any error in the syntax??!

    ReplyDelete
    Replies
    1. Program is correct please copy it and run it in your IDLE Python.

      Delete
  5. Because i also take "yes" as input.

    ReplyDelete
  6. this syntax is not correct. its showing error.
    this is the correct syntax:
    sum = 0
    n = int(input('How many no.s?'))
    for i in range(0,n+1):
    num = int(input('enter a no.:'))
    sum += num
    print('the avg. of the no.s are:',sum/n)

    this is the correct one. pls use this one. u can also try running this one in idle. pls write if any query.

    ReplyDelete
    Replies
    1. please correct that the above written syntax in the comment that for i in range (0,n+1) will be (0,n). the syntax is correct and is working. thank u:)

      Delete
    2. Your code is wrong because we do not know that how many number will be entered by user.

      Delete
    3. If u run the code…. U can see it is perfectly working unlike ur code….. also as we don’t know how many numbers are there therefore n is taken….. the value of n should be the total length of the number…… and num is for the value of the numbers…… pls first RUN THE CODE IN IDLE…….. because the code is totally working and also FIX YOUR CODE, IT IS WRONG!!

      Delete
    4. At first, Question says that we have to enter list of number not n number. So, your code is wrong. I have also written Output so, please ones go thorugh it carefully.

      Delete
    5. Ok if my code is wrong then…… could u pls correct YOUR code…… because that hands off is definitely incorrect……. It’s showing error!! U have also ignored previous comments where the person is clearly saying that the syntax is wrong…… pls first check ur syntax.. and correct it!

      Delete
    6. Code is running properly. So, if code gives error then please share to us on telegram or instagram.

      Delete
  7. Anyone who is running this code.....can u please give a brief which one of the code is incorrect??!! The code written in comment or the code give by pathwalla??!! My request to all pls help the other in choosing the correct syntax. Thank u!!

    ReplyDelete
    Replies
    1. both the codes are correct...... in the upper one u have to type yes to quit and in the code written in the comment section, u first have to give for how many numbers u r doin the avg of and then type the no.s for ex- if u want the avg of 5 no.s then the code will give u option for the input of three no.s. Both are correct and gives the same result and now its upto u to choose which code to use.

      Delete
    2. please correct that in the ex if u want to find the avg of five no.s then the code will give u option for the input of five no.s only..... i mistakenly wrote it will give option for three...... pls mind that..... hope my comment is helpful:)

      Delete
    3. thank u @Kath for ur suggestion :)

      Delete
  8. hi paavan is the person who commented in the name of 'giri free ,i am giri ,not responsible for that comment.Thank you.

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post