佛系计算机二级 & 第八弹

写在前面

第七弹最后一个综合练习部分出了点小问题,为了不影响进度那我先进行第八弹的梳理,之后有机会再把第七弹补上。

Python Round⑧

倒序

animals = ['cow', 'duck', 'cat', 'dog']
s = animals[::-1]
print(s)

另:答案上采用的是另一种方案:

animals = ['cow', 'duck', 'cat', 'dog']
animals.reverse()
print(animals)

删除空白格

word = "   窗前明月光,疑是地上霜。   "
print(word.strip())

输出1-50间的奇数

count = 0	#其实和for理念差不多,都是从0开始的
while count < 50:
    count += 1
    if count % 2 == 0:
        continue
    print(count,end=",")

海龟库

import turtle
for i in range(4):
    turtle.seth(90*i+90)
    turtle.circle(50,90)
    turtle.seth(90*i-90)
    turtle.circle(50,90)
turtle.hideturtle()

对数异常处理

import math
try:
    a = eval(input('请输入底数:'))
    b = eval(input('请输入真数:'))
    c = math.log(b,a)
except ValueError:
    if (a > 0) and (b <= 0):
        print("真数必须大于0")
    elif (b > 0) and (a <= 0):
        print("底数必须大于0")
    elif (b <= 0) and (a <= 0):
        print("真数底数必须大于0")
except ZeroDivisionError:
    print('底数不能为1')
except NameError:
    print('输入必须为实数')
else:
    print(c)

字符转换(chr()、ord())

intxt = input("请输入明文:")
for i in intxt:
    if "a" <= i <= "z":
        print(chr(ord("a")+(ord(i)-ord("z")+3)%26),end=" ")
    elif "A" <= i <= "Z":
        print(chr(ord("A")+(ord(i)-ord("Z")+3)%26),end=" ")
    else:
        print(i,end=" ")

ord()函数主要用来返回对应字符的ascii码
chr()主要用来表示ascii码对应的字符

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人生苦短我愛Python

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值