[Python]Python基础趣讲精练

第一次家庭作业

  • 完成环境安装和环境测试
  • 使用print方法打印出来你的姓名\年龄\爱好
  • 使用print打印一个心形出来
  • 生成一个具有8位随机码,随机码包括a-z,A-Z,0-9

1. 完成环境安装和环境测试

2. 使用print方法打印出来你的姓名\年龄\爱好

print('姓名: %s \n年龄: %d \n爱好: %s'%('worker',23,'读书'))

结果:

姓名: worker
年龄: 23
爱好: 读书

3. 使用print打印一个心形出来

print('''
    ***  ***
  ***********
 *************
   *********
    *******
      ***
''')

结果:

    ***  ***
  ***********
 *************
   *********
    *******
      ***

4. 生成一个具有8位随机码,随机码包括a-z,A-Z,0-9

import string
import random
code = ''.join(random.sample((string.digits + string.ascii_lowercase + string.ascii_uppercase),8))
print(code)

结果:

PdHgFbZ5

posted @ 2020-08-15 09:45  寄生的鱼  阅读(797)  评论(0编辑  收藏  举报