L4.八.excercise2-v2

##学生管理系统 - v2   字典ructure可以

##tip:pycharm左侧的structure可以看脚本结构

student_list = [

  {'name':'小明','age':10,'sex':'male'},

  {'name':'小红','age':13,'sex':'female'},

  {'name':'小李','age':14,'sex':'male'}

]

def show_student():

  print('行号\t\t姓名\t\t年龄\t\t性别\t\t')

  print('-' * 45)

  for i in range(0,len(student_list)):

    #print(student_list[i])         #每一项便利出来,意义同下

    #print(stu)     #  全部信息

    #print(stu['name'])          #取单独的一个行号/姓名/等

    stu_dict = student_list[i]

#字典

  #print

#全部信息

    name=stu_dict['name']    #字典键名取出来

    age=stu_dict['age']

    sex=stu_dict['sex']

    print('{}\t\t\t{}\t\t\t{}\t\t\t{}').format(i+1,name,age,sex))

 

def add_student():

  """   添加学生    """

  new_name = input('请输入姓名')

  naw_age=int(input('请输入你的年龄'))

  new_sex=input('请输入你的性别')

 

  new_stu_dict={

    'name':new_name,

    ‘age’:new_age,

    'sex':new_sex

}

  student_list.append(new_stu_dict)

  print('添加成功')

 

def update_student():

  show_studen()

  num=int(input('修改第几个?'))

  new_name=input('修改后的姓名')

  new_age=int(input('修改后的年龄'))

  new_sex=input('修改后的性别')

 

  stu_dict=student_list[num-1]

  stu-dict['name']=new_name     #修改

  stu_dict['age']=new_age

  stu_dict['sex']=new_sex

  print('修改成功')

 

def delete_student():

  """    删除学生   """

  print("""删除>请输入子操作编号:

        1)按学生编号删除

        2)删除全部学生(谨慎)

""")

  sub_num=int(input('请选择子操作'))

  if sub_num==1:

    stu_num=int(input('要删除第几个学生:'))

    student_list.pop(stu_num-1)

    print('删除成功')

  elif sub_num=2:

    confirm=input('确认删除全部?(Y/N)')

    if confirm=='Y'or confirm == 'y'

      student_list.clear()

      print('删除全部学生成功')

 

def   main():

  #主函数,程序入口

  while True:

    print("""

      1.查询学员姓名

      2.添加学员姓名

      3.修改学员姓名

      4.删除学员姓名

      0.退出程序

      """)

    num=int(input('请输入操作编号'))

    if num == 1:

      show_student()

    elif num==2:

      add_student()

    elif num==3:

      update_student()

    elif num==4:

      delete_student()

    elif  num==0:

        break

#main()

if _name_=='_main_':

  main()

 

转载于:https://www.cnblogs.com/psy0508/p/9986059.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
To plot C versus S for 0 ≤ S ≤ 200, we can use the following MatLab code: ```matlab E = 100; % Exercise price T = 1; % Expiry date r = 0.05; % Risk-free interest rate sigma = 0.3; % Volatility S = linspace(0, 200, 1000); C = zeros(size(S)); for i = 1:numel(S) C(i) = EuropeanCall(S(i), E, r, sigma, T); end plot(S, C); xlabel('S'); ylabel('C'); title('European Call Option Price'); ``` This code first defines the parameters of the option, and then generates a range of values for S between 0 and 200 using the `linspace` function. For each value of S, the code calculates the option price using the `EuropeanCall` function (which can be obtained from various sources). Finally, the code plots the option price as a function of S using the `plot` function. To plot the value of C(S, t) at different values of t between t = 0 and t = T, we can modify the above code as follows: ```matlab E = 100; % Exercise price T = 1; % Expiry date r = 0.05; % Risk-free interest rate sigma = 0.3; % Volatility S = linspace(0, 200, 1000); t = linspace(0, T, 1000); C = zeros(numel(S), numel(t)); for i = 1:numel(S) for j = 1:numel(t) C(i, j) = EuropeanCall(S(i), E, r, sigma, T - t(j)); end end surf(S, t, C); xlabel('S'); ylabel('t'); zlabel('C'); title('European Call Option Price'); ``` This code generates a grid of values for S and t using `linspace`, and then calculates the option price for each combination of S and t using a nested loop. The option price is stored in a matrix `C`, and is plotted as a surface using the `surf` function. As t approaches T, the option price converges to the intrinsic value of the option, which is max(S - E, 0) for a call option. This is because as the expiry date approaches, the option has less time to move in the money, and its time value decreases.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值