Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is going on?
#1
What it needs to do....
Quote:2. InputExpenseNames
First create an empty list for expense items. Next, enter a loop that iterates for as long as the user
responds that there are more item names to enter. In the loop, display a message asking the user to
input the name of an expense item, then input the name and append it to the list. Then input a
response to the question whether there are more item names.
After the loop ends, return the expense items list.
3. InputExpenseAmounts
Create an empty list for expense amounts. Enter a loop that uses the size (you may use the len
function) of the expense items list to determine number of iterations. For each iteration, display a
message that says:
How much was spent on xxxxxxxxxx expense item?
where xxxxxxxxxx is replaced by the name from the expense_items_list corresponding to the current
iteration. The amount should then be input and appended to the expense amounts list. Input
validation should be done including using try … except … to ensure a number was entered.
After the loop ends, return the expense amounts list.


What I have...
def InputExpenseNames():
    expenseItems = []    
    name = input("Enter expense name (q for quit):")    
    while name != "q" :    
        expenseItems.append(name)    
        name = input("Enter expense name (q for quit):")    
    return expenseItems
        
#expense amounts expenseAmounts
def InputExpenseAmounts(expenseItems):
    expenseAmounts = []
    print('How much was spent on ')
    for i in expenseItems:
        amount = int(input(i + 'expense items?'))
        expenceAmount.append(amount)
   return expenseAmounts
What I am getting is it goes back to the main_menu and not allowing me to input. Recommendations on how to fix this so I can input into the expenseItems list.


This is what I have def in main...
while choice != quitOp:
        main_menu()
        choice = int(input('Enter expense report option: '))

        if choice == nameOp:
            InputExpenseNames()

        elif choice == amountOp:
            InputExpenseAmounts(expenseItems)

        elif choice == reportOp:
            displayExpenseReport(expenseItems, expenseAmounts)
             
        else:
            print('Thank you, goodbye')
Reply


Messages In This Thread
What is going on? - by zimmytheflygirl - Jun-28-2024, 02:59 PM
RE: What is going on? - by deanhystad - Jun-28-2024, 07:03 PM
RE: What is going on? - by zimmytheflygirl - Jun-28-2024, 07:43 PM
RE: What is going on? - by deanhystad - Jun-28-2024, 08:34 PM
RE: What is going on? - by zimmytheflygirl - Jun-29-2024, 12:23 AM
RE: What is going on? - by Pedroski55 - Jun-29-2024, 06:24 AM
RE: What is going on? - by LauraB - Jun-29-2024, 06:31 AM
RE: What is going on? - by Pedroski55 - Jun-29-2024, 07:08 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020