defOdd_For(n):
odds =[]#使用for循环向odds列表中添加数据# 请在此添加实现代码 ## ********** Begin *********#for i inrange(1,n+1):if(i %2!=0):
odds.append(i)return odds
# ********** End **********#return odds
defOdd_While(n):
odds =[]#使用while循环向odds列表中添加数据# 请在此添加实现代码 ## ********** Begin *********#
i =1while(i <= n):if(i %2!=0):
odds.append(i)
i +=1return odds
# ********** End **********#return odds
第2关:计算原子能级
题目
代码
defEnLevel(n):#请在这里编写程序,完成本关任务# 请在此添加实现代码 ## ********** Begin *********#
me=9.1094e-31
e=1.6022e-19
epsilon0=8.8542e-12
h=6.6261e-34
En =-(me*e**4)/(8*epsilon0**2*h**2)*1/(n*n)print("%.5e"%En)# ********** End **********#
第3关:嵌套循环 - 跃迁能量表
题目
代码
defEnList(maxn):# 请在这里编写程序,打印跃迁能量表
me =9.1094e-31
e =1.6022e-19
epsilon0 =8.8542e-12
h =6.6261e-34print(" |能级1\t\t能级2\t\t能级3\t\t能级4\t\t能级5")print("--------------------------------------------------------------------------------")
list_en =[]
list_i =[0,0,0,0,0]for i inrange(1,6):
list_en.append(-(me * e **4)/(8*(epsilon0 **2)* h **2)*1/(i * i))for i inrange(6, maxn +1):
list_en.append(-(me * e **4)/(8*(epsilon0 **2)* h **2)*1/(i * i))for i inrange(1, maxn +1):for j inrange(1,6):
list_i[j -1]= list_en[j -1]- list_en[i -1]if list_i[j -1]==0.000000E+00:
list_i[j -1]=-0.000000E+00print('{:} | {:.6E}\t{:.6E}\t{:.6E}\t{:.6E}\t{:.6E}\t'.format(i,list_i[0], list_i[1], list_i[2], list_i[3],list_i[4]))