A few comments:
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 wantnew_salary == 200000
.- That still won't work, because
new_salary
, like everything you get frominput
, is a string; you can fix this withnew_salary = int(input(...))
. - Your code doesn't actually change the salary in the dictionary
Chelsea_Salaries_2014
; to do that, assign the new value back to the dictionaryChelsea_Salaries_2014[search_input][1] = new_salary
. - 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?