Write a procedure that allows a person to input a player's name and change their salary [closed]

StackOverflow https://stackoverflow.com/questions/23244652

  •  08-07-2023
  •  | 
  •  

Question

This is how far I have got with this but I am not sure how to call the procedure again:

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']

search_input = input('Welcome Jose. What player would you like to search for? ')
print('His Current Salary is £' + str(Chelsea_Salaries_2014[search_input][1]))
print()
new_salary = input('What would you like to change his salary to? ')

 if new_salary is 200000:
    print('Salary has been changed to £' + new_salary)
 else:
    if new_salary == >100000:
       print('This salary is ridiculous!')
Was it helpful?

Solution

A few comments:

  1. new_salary is 200000 checks identity (whether the two things are the same object) not equality (whether the two things have the same value); you want new_salary == 200000.
  2. That still won't work, because new_salary, like everything you get from input, is a string; you can fix this with new_salary = int(input(...)).
  3. Your code doesn't actually change the salary in the dictionary Chelsea_Salaries_2014; to do that, assign the new value back to the dictionary Chelsea_Salaries_2014[search_input][1] = new_salary.
  4. What values are you checking for? Should the value be updated if the new value is less than or equal to £200,000? If you get warned that it's ridiculous, should it be updated anyway? You need to think more carefully about what the logic is. For example, I think your first check should be <= 200000, but then you never reach the check for <= 100000.

I think you want something like this:

def change_salary(salaries):
    search_input = input('Welcome Jose. What player would you like to search for? ')
    print('His Current Salary is £{0:,}'.format(salaries[search_input][1]))
    new_salary = int(input('What would you like to change his salary to? '))
    if new_salary <= 200000:
        salaries[search_input][1] = new_salary
        print('Salary has been changed to £{0:,}'.format(new_salary))
    else:
        print('This salary is ridiculous!')

You can now call this repeatedly, like:

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

Once you have that working, you might want to consider some input validation in change_salary - i.e. does the user always enter an integer for new_salary? Is search_input always a valid key? What if they only enter part of the name?

OTHER TIPS

Try this one:

search_input = input('Welcome Jose. What player would you like to search for? ')
print('His Current Salary is £' + str(Chelsea_Salaries_2014[search_input][1]))
print()
new_salary = int(input('What would you like to change his salary to? '))

if new_salary < 200000:
    print('Salary has been changed to £' + new_salary)
else:
    print('This salary is ridiculous!')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top