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
>>>
Maza ni aaya ðŸ˜ðŸ˜ðŸ˜ðŸ˜ðŸ˜ðŸ˜
ReplyDeleteThis is not comedy show !!
DeleteSahi baat hai...Maja nahi aaya..
DeleteThank you for the solutions
ReplyDeleteWelcome : )
DeleteYes, Please tell me question.
ReplyDeletewhat is 'feq' referring over here(in the program)?
ReplyDeleteIt is counting the number of integer entered by user.
Deletethank you:)
ReplyDeleteWelcome : )
Deletethe program is showing error. is there any error in the syntax??!
ReplyDeleteProgram is correct please copy it and run it in your IDLE Python.
DeleteBecause i also take "yes" as input.
ReplyDeletethis syntax is not correct. its showing error.
ReplyDeletethis 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.
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:)
DeleteYour code is wrong because we do not know that how many number will be entered by user.
DeleteIf 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!!
DeleteAt 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.
DeleteOk 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!
DeleteCode is running properly. So, if code gives error then please share to us on telegram or instagram.
DeleteAnyone 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!!
ReplyDeletePlease watch the video.
Deleteboth 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.
Deleteplease 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:)
Deletethank u @Kath for ur suggestion :)
Deleteur welcome :)
Deletehi paavan is the person who commented in the name of 'giri free ,i am giri ,not responsible for that comment.Thank you.
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )