[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