-4

I asked this earlier but it was not answered (my fault, I didn't put a question). I need to make a menu with 4 options but I do not know how to link the user_input to the actual 1,2,3,4 programs. Please help....

Chelsea_Salaries_2014 = {'Jose Mourinho':[53, 163500, 'Unknown']}
Chelsea_Salaries_2014['Eden Hazard']=[22, 185000, 'June 2017']
Chelsea_Salaries_2014['Fernando Torres']=[29, 175000, 'June 2016']
Chelsea_Salaries_2014['John Terry']=[32, 175000, 'June 2015']
Chelsea_Salaries_2014['Frank Lampard']=[35, 125000, 'June 2014']
Chelsea_Salaries_2014['Ashley Cole']=[32, 120000, 'June 2014']
Chelsea_Salaries_2014['Petr Cech']=[31, 100000, 'June 2016']
Chelsea_Salaries_2014['Gary Cahill']=[27, 80000, 'June 2017']
Chelsea_Salaries_2014['David Luiz']=[26, 75000, 'June 2017']
Chelsea_Salaries_2014['John Obi Mikel']=[26, 75000, 'June 2017']
Chelsea_Salaries_2014['Nemanja Matic']=[25, 75000, 'June 2019']
Chelsea_Salaries_2014['Marco Van Ginkel']=[20, 30000, 'June 2018']
Chelsea_Salaries_2014['Ramires']=[26, 60000, 'June 2017']
Chelsea_Salaries_2014['Oscar']=[21, 67500, 'June 2017']
Chelsea_Salaries_2014['Lucas Piazon']=[19, 15000, 'June 2017']
Chelsea_Salaries_2014['Ryan Bertrand']=[23, 35000, 'June 2017']
Chelsea_Salaries_2014['Marko Marin']=[27, 35000, 'June 2017']
Chelsea_Salaries_2014['Cesar Azpilicueta']=[23, 55000, 'June 2017']
Chelsea_Salaries_2014['Branislav Ivanovic']=[29, 67500, 'June 2016']
Chelsea_Salaries_2014['Ross Turnbull']=[22, 17000, 'June 2017']
Chelsea_Salaries_2014['Demba Ba']=[28, 65000, 'June 2016']
Chelsea_Salaries_2014['Oriol Romeu']=[22, 15000, 'June 2015']

user_input = (int('Welcome! What would you like to do? 1: Print the total salaries bill. 2: Print the average salary. 3: Change a players salary. 4: Quit. '))

if user_input == 1:
    print(sum(i[1] for i in Chelsea_Salaries_2014.values()))
else:
    if user_input == 2:
       print(sum(i[1] for i in Chelsea_Salaries_2014.values()))/len(Chelsea_Salaries_2014)
    else:
        if user_input == 3:
            def change_salary(Chelsea_Salaries_2014):
                search_input = input('What player would you like to search for? ')
                print('His Current Salary is £{0:,}'.format(Chelsea_Salaries_2014[search_input][1]))
                new_salary = int(input('What would you like to change his salary to? '))
            if new_salary <= 200000:
                Chelsea_Salaries_2014[search_input][1] = new_salary
                print('Salary has been changed to £{0:,}'.format(new_salary))
            else:
                print('This salary is ridiculous!')

            while True:
                change_salary(Chelsea_Salaries_2014)
                choice = input("Go again? y/n ")
                if choice.lower() in ('n', 'no'):
                        break
        else:
            if user_input == 4:
                print('Goodbye!')

1 Answers1

1

Your code doesn't appear to prompt for input anywhere. Is that the issue?

user_input = int( input("your prompt goes here") )
# PYTHON3

user_input = int( raw_input("your prompt goes here") )
# PYTHON2

As an aside: if you don't have to use your user's input as a number (e.g. you don't need to do any math with it) then don't cast it to int and test for if user_input == "1" rather than if user_input == 1

Adam Smith
  • 45,072
  • 8
  • 62
  • 94
  • 1
    +1 for being 10 second faster than me with the bloody correct answer :) – ElmoVanKielmo Apr 23 '14 at 15:25
  • 1 works but when I do 2 it says that it has an 'unsupported operand type' – Calvin_Medcalf Apr 23 '14 at 15:34
  • 3 doesn't work and just says new salary is not defined even though I have defined it the line above (new_salary = int(input(...) – Calvin_Medcalf Apr 23 '14 at 15:34
  • @Calvin_Medcalf I don't know why `2` doesn't work, your `sum` looks correct. Maybe I'm missing something. `3` doesn't work because your indentation is wrong. – Adam Smith Apr 23 '14 at 15:43
  • @Calvin_Medcalf as an aside, why aren't you using `elif`s? `if user_input == 1: # do stuff; elif user_input == 2: # do other stuff` instead of `else: if user_input==2` which ends up making a big ugly tree inside your code. – Adam Smith Apr 23 '14 at 15:45
  • @Calvin_Medcalf the four lines from `if new_salary <= 200000:` are incorrectly indented - they should be *inside* `change_salary`, i.e. one tab deeper – jonrsharpe Apr 24 '14 at 10:01