练习4

  1. 猜数字

#!/usr/bin/env python

#coding:utf-8

import random

num = random.randint(0,9)

while True:

user_num = raw_input("please input a num: ")

user_num = int(user_num)

if user_num == num:

print ‘success‘

for i in range(1,8):

print ‘*‘*i

break

else:

print ‘error‘

2.创建文件夹

#!/usr/bin/env python

#coding:utf-8

import os

depts = [‘销售部‘,‘人事部‘,‘技术部‘]

for dept in depts:

try:

os.mkdir(dept)

except OSError as e:

print ‘文件[%s]已经存在,因为 [%s]‘ % (dept,e.strerror)

时间: 2024-10-10 18:16:00