# -*- coding:cp936 -*- '''------------------------------------------------------ 【程序填空】 --------------------------------------------------------- 题目:企业发放的奖金根据利润提成。利润(i)低于或等于10万元 时,奖金可提10%;利润高于10万元,低于20万元时,低于 10万元的部分按10%提成,高于10万元的部分,可可提成7.5% ;20万到40万之间时,高于20万元的部分,可提成5%;40万 到60万之间时高于40万元的部分,可提成3%;60万到100万 之间时,高于60万元的部分,可提成1.5%,高于100万元时, 超过100万元的部分按1%提成,从键盘输入当月利润i,求 应发放奖金总数? ---------------------------------------------------------- 注意:除要求填空的位置之外,请勿改动程序中的其他内容。 ------------------------------------------------------''' def get_reward(I): rewards = 0 if I <= 10: #**********SPACE********** rewards = I + I * 0.1 #**********SPACE********** elif (I > 10) and (________________): rewards = (I - 10) * 0.075 + get_reward(10) elif (I > 20) and (I <= 40): rewards = (I - 20) * 0.05 + get_reward(20) elif (I > 40) and (I <= 60): rewards = (I - 40) * 0.03 + get_reward(40) elif (I > 60) and (I <= 100): #**********SPACE********** rewards = (________________) * 0.015 + get_reward(60) else: #**********SPACE********** rewards = get_reward(100) + (________________) * 0.01 return rewards def main(): num = int(input("请输入今年的公司净利润:")) # 计算公司的年度奖金,单位:万元 print("发放的奖金为:", get_reward(num / 10000) * 10000) if __name__ == '__main__': main()
时间: 2023-07-01 17:25:47 浏览: 65
空格填写如下:
```python
def get_reward(I):
rewards = 0
if I <= 10:
rewards = I + I * 0.1
elif (I > 10) and (I <= 20):
rewards = (I - 10) * 0.075 + get_reward(10)
elif (I > 20) and (I <= 40):
rewards = (I - 20) * 0.05 + get_reward(20)
elif (I > 40) and (I <= 60):
rewards = (I - 40) * 0.03 + get_reward(40)
elif (I > 60) and (I <= 100):
rewards = (I - 60) * 0.015 + get_reward(60)
else:
rewards = get_reward(100) + (I - 100) * 0.01
return rewards
```
其中,第一个空格填写 `rewards = I + I * 0.1`。
相关问题
stbc-ofdm代码
好的,下面给你提供一个简单的STBC-OFDM代码做参考:
```python
import numpy as np
import matplotlib.pyplot as plt
# OFDM参数设置
N = 64 # 子载波数
cp_len = 16 # 循环前缀长度
pilot_freq = 8 # 导频间隔
pilot_symbol = np.array([1, -1, 1, 1]) # 导频序列
data_len = 48 # 数据长度
data_symbol = np.random.randint(0, 2, data_len) * 2 - 1 # 随机生成BPSK调制数据
mod_order = 2 # 调制阶数,2表示BPSK
EbN0_dB = 30 # 信噪比,单位dB
# STBC编码参数
Nt = 2 # 天线数
code_rate = 1 # 编码速率,1表示ALAMOUTI编码,0.5表示Space-Time Block Coding
if code_rate == 1:
T = np.array([[1, 1j], [1j, -1]]) / np.sqrt(2)
else:
T = np.array([[1, 0], [0, 1j]])
# 生成OFDM符号
if mod_order == 2:
data_mod = data_symbol
else:
raise NotImplementedError("此处只实现了BPSK调制")
data_mod_reshape = data_mod.reshape((-1, N))
data_mod_stbc = np.zeros((data_mod_reshape.shape[0], Nt, N), dtype=np.complex)
data_mod_stbc[:, 0, :] = data_mod_reshape.dot(T[0, :])
data_mod_stbc[:, 1, :] = data_mod_reshape.dot(T[1, :])
data_ofdm = np.zeros((data_mod_reshape.shape[0], Nt, N), dtype=np.complex)
for i in range(data_mod_reshape.shape[0]):
for j in range(Nt):
data_ofdm[i, j, :] = np.fft.ifft(data_mod_stbc[i, j, :], N)
data_ofdm[i, :, 0:cp_len] = data_ofdm[i, :, -cp_len:]
data_ofdm[i, 1, 0:cp_len] = 0
data_ofdm = data_ofdm.reshape(-1, Nt * N)
pilot = np.zeros((data_ofdm.shape[0],), dtype=np.complex)
pilot[::pilot_freq] = pilot_symbol
tx_signal = np.concatenate([pilot[:, np.newaxis], data_ofdm], axis=1)
# 加噪声
Es = np.sum(np.abs(tx_signal) ** 2, axis=1) / (tx_signal.shape[1])
Eb = Es / np.log2(mod_order)
N0 = Eb / 10 ** (EbN0_dB / 10)
noise = np.random.randn(*tx_signal.shape) * np.sqrt(N0 / 2) + 1j * np.random.randn(*tx_signal.shape) * np.sqrt(N0 / 2)
rx_signal = tx_signal + noise
# 接收端处理
rx_signal = rx_signal.reshape(-1, Nt, N)
rx_symbol = np.zeros((rx_signal.shape[0], N), dtype=np.complex)
for i in range(rx_signal.shape[0]):
for j in range(N):
h_ij = np.array([[np.random.randn(), np.random.randn()], [np.random.randn(), np.random.randn()]]) / np.sqrt(2)
rx_symbol[i, j] = rx_signal[i, :, j].dot(h_ij).dot(np.linalg.inv(T))
rx_symbol[i, 0:pilot_freq:pilot_freq+1] = 0 # 去掉导频
rx_symbol = rx_symbol.reshape(-1)
rx_data = np.zeros((rx_symbol.shape[0],), dtype=np.int8)
rx_data[rx_symbol > 0] = 1
# 计算误码率
err_num = np.sum(rx_data != data_mod)
print("误码率:", err_num / data_mod.shape[0])
# 绘制调制后的信号和接收信号的频谱
fig, ax = plt.subplots(2, 1, figsize=(6, 6))
ax[0].plot(tx_signal[0, :].real)
ax[0].plot(tx_signal[0, :].imag)
ax[0].set_title("Transmitted Signal")
ax[1].plot(np.fft.fftshift(np.abs(np.fft.fft(tx_signal[0, :]))))
ax[1].set_title("Transmitted Spectrum")
fig.tight_layout()
fig, ax = plt.subplots(2, 1, figsize=(6, 6))
ax[0].plot(rx_signal[0, :, :].real.T)
ax[0].plot(rx_signal[0, :, :].imag.T)
ax[0].set_title("Received Signal")
ax[1].plot(np.fft.fftshift(np.abs(np.fft.fft(rx_signal[0, :, :].reshape(-1)))))
ax[1].set_title("Received Spectrum")
fig.tight_layout()
plt.show()
```
这段代码实现了一个基于ALAMOUTI编码的STBC-OFDM系统,包含随机生成BPSK数据、STBC编码、OFDM调制、加噪声、接收端处理、误码率计算和绘制调制后的信号和接收信号的频谱等步骤。你可以根据自己的需要进行修改和扩展。
6. # -*- coding:cp936 -*- '''------------------------------------------------------ 【程序设计】 --------------------------------------------------------- 题目:d 是一个字典,内容如下: d = {123:"123", 456:"456", 789:"789"} 请补充如下代码,将字典 d 中所有键以列表形式输出 --------------------------------------------------------- 注意:部分源程序给出如下。请勿改动其它函数中的任何内容, 仅在函数的注释标志之间填入所编写的若干语句。 先将程序段中横线部分去掉,然后填写正确的程序内容 -----------------------------------------------------''' #**********Program********** d = {123:"123", 456:"456", 789:"789"} print(___①_) #********** End **********
# -*- coding:cp936 -*-
'''------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:d 是一个字典,内容如下:
d = {123:"123", 456:"456", 789:"789"}
请补充如下代码,将字典 d 中所有键以列表形式输出
---------------------------------------------------------
注意:部分源程序给出如下。请勿改动其它函数中的任何内容,
仅在函数的注释标志之间填入所编写的若干语句。
先将程序段中横线部分去掉,然后填写正确的程序内容
-----------------------------------------------------'''
#**********Program**********
d = {123:"123", 456:"456", 789:"789"}
print(list(d.keys())) #使用 list() 函数将字典的键转换为列表形式并输出
#********** End **********