python - 给定代码中的错误是什么?
问题描述
一家公司决定给员工发奖金。男性员工可获得 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))
解决方案
好的,你不能只输入:
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
推荐阅读
- python - 删除“找不到命令”错误 discord.py
- c# - 如何将 ColorPicker 添加到 Datagrid Cell - MVVM Light
- javascript - 使用 json_encode 和 PHP 使用 jQuery 在另一个 div 中添加一个类
- c# - 以可访问的方式添加事件处理程序
- asp.net-mvc - 当我尝试将多个参数传递给局部视图时出现错误
- java - 如何使我的插件有助于从 Eclipse 平台中的现有菜单将菜单项添加到现有子菜单中?
- javascript - 通过 axios 发布数据而不“包装”密钥?
- swift - 调整窗口大小后,swift NSCollectionView 布局错误
- python - Matplotlib 绘图很慢
- javascript - 重写 with(this) 语句