jeapedu 21 字符串chr函数

链接: https://pan.baidu.com/s/1ggQLYhH 密码: i7st

# 3 random.randint(100000,999999) 
#   1) if 4 and 7 in it
#   2) if 4 and 7 not in it, whether 6 and 8 in it
#   3) print 4 and 7 pos
import random
i = 0
while i < 20:
    x = random.randint(100000,999999)
    #print(x, str(x),type(str(x)))
    s = str(x)
    #if "4" in s and "7" in s:
        #print("has 4 and 7", s)
    if "4" not in s and "7" not in s:
        if "6" in s or "8" in s:
            print("has 6 or 8", s)
    #else:
        #print(s)
    i += 1

import random
i = 0
while i < 20:
    x = random.randint(100000,999999)
    s = str(x)
    if "4" in s or "7" in s:
        print(s, end=' ')
        k = 0
        while k < len(s):
            if s[k] == "4" or s[k] == "7":
                print(s[k], k, end=' ')
            k += 1
        print("")
    i += 1

# 4 format a string like "a01b02c03...y25z26"
# string
s = "abcdefghijklmnopqrstuvwxyz"
#   "12345678901234567890123456"
i = 0
a = ''
while i < len(s):
    a += s[i] + '%02d'%(i+1)
    i += 1
print(a)

help(chr)
print(chr(65))
print(chr(97))
print(chr(98))

# chr()
x = 97
print(chr(x))
i = 0
a = ''
while i < 26:
    a += chr(x + i) + "%02d" %(i + 1)
    i += 1
print(a)

# 5 use chr(ascii to character) and ord(character to ascii)
#   and int(string to integer) to translate
# "#98#102#132#12#66#90#22#"

s = "#98#102#132#12#66#90#22#"
i = 0
while i < len(s):
    tmp = ''
    if s[i] != '#':
        tmp += s[i]
        j = i + 1
        while s[j] != '#':
            tmp += s[j]
            j += 1
        i += len(tmp)
    elif s[i] == '#':
        i += 1
    if tmp != '':
        print(chr(int(tmp)))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值