总/平均/变动薪水 1,2,3,4 菜单 [英] Total/Average/Changing Salary 1,2,3,4 Menu

查看:75
本文介绍了总/平均/变动薪水 1,2,3,4 菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更改您的程序,以便经理可以从主菜单中选择四个选项:

Change your program so there is a main menu for the manager to select from with four options:

  1. 打印每周总工资单.
  2. 打印平均工资.
  3. 更改球​​员的薪水.
  4. 退出

当我运行程序时,我输入数字 1,程序停止.如何将其链接到以下 4 个程序?

When I run the program, I enter the number 1 and the program stops. How do I link it to the 4 below programs?

计划:

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!')

推荐答案

把原始输入放在一边.

 while True:
 user_input = raw_input("Welcome!...")
 if user_input == 1:
  ...
 elif user_unput == 2:
  ...
 else:
  print "this salary is ridic..."

在完成 1,2,3... 输入后,询问用户是否愿意做其他事情 y/n,如果 n:break,这将结束循环.如果是 y,则循环再次开始并要求另一个用户输入.

After completing a 1,2,3... input ask the user if they would like to do something else y/n, if n: break, this will end the loop. If y, the loop begins again and asks for another user input.

这篇关于总/平均/变动薪水 1,2,3,4 菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆