首页 > 解决方案 > 给定代码中的错误是什么?

问题描述

一家公司决定给员工发奖金。男性员工可获得 5% 的奖金,女性员工可获得 10% 的奖金。如果员工的工资低于 10000,则员工将获得 2% 的额外奖金。

计算工资以及必须给予的奖金。

我的代码如下所示:

a = input('Enter your name here: ')
b = int(input('your salary here: '))
c = input('your gender here (M/F) : ')
if b < 10000 and c == 'M':
    print(str(a) + ' your salary with bonus is ' + str(b * 1.07))
elif b < 10000 and c == 'F':
    print(str(a) + ' your salary with bonus is ' + str(b * 1.12))

if b >= 10000 and c == 'M':
    print(str(a) + ' your salary with  bonus is '+ str(b * 1.05))

elif b >= 10000 and c=='F':
        print(str(a) + ' your salary with  bonus is '+ str(b * 1.1))

标签: pythonpython-3.x

解决方案


好的,你不能只输入:

if b<10000 and c=='M'  :
    # code
else:
b<10000 and c=='F'

如果要检查两个条件,则需要两个 if,如下所示:

if b<10000 and c=='M'  :
    # code
else:
  if b<10000 and c=='F' :
    # code

推荐阅读