import random def generate_code(code_len=4): all_charts = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' last_pos = len(all_charts) -1 code = '' for _ in range(code_len): index = random.randint(0,last_pos) code += all_charts[index] return code #如果和for同行就会显示外围数据,如果加到里面就是第一层遍历完成 def main(): print(generate_code(5)) if __name__ == '__main__': main()
from random import randint face = randint(1, 6) if face == 1: result = '唱首歌' elif face == 2: result = '跳个舞' elif face == 3: result = '学狗叫' elif face == 4: result = '做俯卧撑' elif face == 5: result = '念绕口令' else: result = '讲冷笑话' print(result)
随机生成
标签:__,elif,code,python,random,face,随机,字符串,result From: https://www.cnblogs.com/kevin-yang123/p/17021416.html