程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python workbook, a small program every day, question 0001

編輯:Python

This paper is finally updated at 1163 Days ago, , The information may have developed or changed .

requirement

As Apple Store App Indie developer , You're going to have a limited time promotion , For your application Generate activation code ( Or coupons ), Use Python How to generate 200 Activation codes ( Or coupons )?

Code

import random
import string
str=string.ascii_uppercase+string.digits
def getKey(length):
key=''
for i in range(0,int(length)):
key+=random.choice(str)
return key
def main():
length=input('please input length of key')
number=input('please input number of key')
keys=[]
for i in range(0,int(number)):
key=getKey(length)
if not key in keys:
keys.append(key)
else:
i-=1
path='temp/keys.txt'
with open(path,'w') as file:
for item in keys:
file.write(item+'\n')
main()

Post Views: 321


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved