I am in a beginner Python course and I need some help getting my code started.
I need to create a tool that asks how many businesses you want to analyze, and after inputting a number of businesses, it will say "How many employees at business (1)? then for the input of employees, it will ask "What is the salary of the employee (1), then (2) then (3), etc.
After this, I have to do some math and average everything, but that is much easier than lists. Please help, I don't know how to get started and I am really stressed out
print("Welcome to Business Salary Analyzer")
repeat == "yes"
numberbusinesses = []
while repeat == "yes":
numberbusinesses = int(input(How many businesses would you like to analyze? "))
CodePudding user response:
- Line 2: The
==
checks is 2 variables are same or not. So you need to changerepeat == "yes"
torepeat = "yes"
(=
means assign value). - Line 4: This is not a bug, but you can change
while repeat == "yes":
towhile True:
to reduce lines (you can also delete line 2). - Line 5: You have
How many businesses would you like to analyze? "
which will cause you an error because it has unclosed string. Just close it.
CodePudding user response:
it's a simple task
print('---------')
no_of_b = int(input('Enter The number of bussiness'))
for nob in range(no_of_b):
no_of_employee = input(f'Enter The number of employee {nob 1} : ')
salary = []
for noe in range(no_of_employee):
sal = int(input(f'Enter the salary of {noe 1}: '))
salary.append(sal)
print(salary)
# here come your logic
CodePudding user response:
From what I gather, you're trying to add to a list a variable amount of times depending on what the user inputs. You could do something like:
num = int(input("How many businesses? "))
employeeCount = [] #This will hold the amount of employees for each business
salaries = [] #This list will hold lists of salaries for each business (a list of lists)
for i in range(num): #for each business
employeeCount.append(int(input("Number of employees for business " i))) #add number of employees in this business to employeecount list
bizSalaries = [] #this will hold the salaries for each employee in the current business
for j in range(employeeCount[i]): #for each employee in business i
bizSalaries.append(int(input("What is the salary of employee " j " in business " i)))
salaries.append(bizSalaries) #Add our list of salaries for this business to a list which holds the list of salaries for all businesses
Now that we've gathered our data, we can do whatever averaging math you'd like.