[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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM