• 作业二
      字符串 s = ‘this is a book’ 1.请将字符串里的book替换成apple ‘
      ‘2.请用程序判断该字符串是否以this开头 ‘
      ‘3.请用程序判断该字符串是否以apple结尾 ‘
      ‘4.如字符串的末尾有一个@,请将其删除

      1. st = 'this is a book'
      2. print(st.replace('book','apple'))
      3. st_input =input('请输入:')
      4. if st_input.startswith('this'):
      5. print('是this开头的')
      6. elif st_input.endswith('apple'):
      7. print('是apple结尾的')
      8. elif st_input.strip('@'):
      9. st_input.replace('@','')
    • 作业三

      将列表 li [2, 5, 6, 4, 9, 10, 23]
      1. 降序输出
      2. 降序排序后利用切片输出23, 9, 5,2

      1. li = [2, 5, 6, 4, 9, 10, 23]
      2. li.reverse()
      3. print(li)
      4. print(li[::2])
    • 作业四

      1. st = input('请输入:')
      2. if len(st) > 3 and not st.endswith('ing'):
      3. print(st+'ing')
      4. elif st.endswith('ing'):
      5. print(st+'ly')
      6. elif len(st) < 3:
      7. print(st)

      �