use NESTED IF..ELSE to solve this problem: There are 7 people. Write a JUST BASI
ID: 671535 • Letter: U
Question
use NESTED IF..ELSE to solve this problem:
There are 7 people. Write a JUST BASIC program to ask the user to enter the yearly income of each person. As the user enters an income, count the number of people who belong to each of the following groups
a)Those who made less than or equal to 30000
b) Those who made above 30000 and less than or equal to 50000
c) Those who made above 50000 and less than or equal to 75000
d) Those who made above 75000
Also, display the total (Combined) earning made by all people. (Must run on a JUST BASIC complier... )
Explanation / Answer
arr=list()
i=0
for i in range(7):
print "enter income of user %d",i
num=int(raw_input("num:"))
arr.append(num)
grp1=0
grp2=0
grp3=0
grp4=0
count=0
for i in range(7):
if arr[i]<=30000:
grp1=grp1+1
elif arr[i]>30000 and arr[i]<=50000:
grp2=grp2+1
elif arr[i]>50000 and arr[i]<=75000:
grp3=grp3+1
else:
grp4=grp4+1
print "Users who's income is less than or equal to 30000 are %d ",grp1
print "Users who's income is greater than 30000 and less than or equal to 50000 are %d ",grp2
print "Users who's income is greater than 50000 and less than or equal to 75000 are %d ",grp3
print "Users who's income is greater than 75000 are %d ",grp4
for i in range(7):
count=count+arr[i]
print "overall income is:",count
This is written in python,do tell me if u need an explaination.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.