[Python]Python基础趣讲精练

第一次家庭作业

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

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

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

print('姓名: %s 
年龄: %d 
爱好: %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

原文地址:https://www.cnblogs.com/jsdy/p/13507616.html