第一周作业

# count=0
# while count<=11:
# if count != 7:
# count += 1
# print (count)
# 1、使用while循环输出1 2 3 4 5 6 8 9 10
# 2、求1-100的所有数的和
# count=1
# i=0
# while count <=100 :
# i +=count
# count +=1
# print (i)
#3、输出 1-100 内的所有奇数
# count=1
# while count <=100:
# count += 1
# if count % 2 ==1:
# print (count)
#3、输出 1-100 内的所有偶数
# 5、求1-2+3-4+5 ... 99的所有数的和
# count=1
# res=0
# while count <= 99:
# if count % 2 ==0:
# res-=count
# else:
# res+=count
# count += 1
# print (res)

# 用户登录(三次重试机会)
# count=0
# while True:
# if count==3:
# print('sanci jieshu')
# break
# u=input('u>>: ')
# p=input('p>>: ')
# if u=='wh' and p == '123':
# print ('login ok')
# break
# count+=1



# count=0
# while True:
# if count==3:
# print('sanci jieshu')
# break
# u=input('u>>: ')
# p=input('p>>: ')
# if u=='wh' and p == '123':
# print ('login ok')
# break
# count+=1


# 1 使用while循环输出 1 2 3 4 5 6 8 9 10
# count=1
# while count <=10:
# if count ==7:
# count +=1
# continue
# print(count)
# count +=1
# 1-100所有数的和
# count=1
# a=0
# while count <=100:
# a +=count
# count +=1
# print(a)


#输出1-100内的所有奇数
# count=0
# while count <=100:
# count +=1
# if count % 2 ==1:
# print(count)

#输出1-100内的所有偶数
# count=0
# while count <=100:
# count +=1
# if count % 2 ==0:
# print(count)


# 求1-2+3-4+5 ... 99的所有数的和
# count=1
# i=0
# while count <=99:
# if count % 2==0:
# i -=count
# else:
# i +=count
# count +=1
# print(i)
# count=1
# res=0
# while count <= 99:
# if count % 2 ==0:
# res-=count
# else:
# res+=count
# count += 1
# print (res)



# strip
#name='*wh**'
#print(name.strip('*'))
#print(name.lstrip('*'))
#print(name.rstrip('*'))

# startswith,endswith
# name='wh_aa'
# print(name.endswith('aa'))
# print(name.startswith('wh'))

# replace
# name='wh say: i have one tesla,my name is wh'
# print(name.replace('wh','aa',1))

# formet的三种玩法
# res='{} {} {}'.format('wh',21,'male')
# res='{1} {0} {1}'.format('wh',21,'male')
# res='{name} {age} {sex}'.format(sex='male',name='wh',age=21)


#find,rfind,index,rindex,count
# name='wh say hello'
# print(name.find('0',1,3)) #顾头不顾尾,找不到则返回-1不会报错,找到了则显示索引
# print(name.index('e',2,4)) #同上,但是找到会报错
# print(name.split('/',1)) #顾头不顾尾,如果不指定范围则查找所有


#split
# name='root:x:0:0::/root/bin/bash'
# print(name.split(':')) #默认分隔符为空格
# name='c=/a/b/c/d/.txt' #只想拿到顶级目录
# print(name.split('/')1)

# name='a/b/c'
# print(name.rsplit('/',1))

#join
# tag=''
# print(tag.join(['wh','say','hello','wold'])) #可迭代对象是字符串

#center,ljust,rjust,zjust
# name='wh'
# print(name.center(30,'_'))
# print(name.ljust(30,'*'))
# print(name.rjust(30,'*'))
# print(name.zfill(50)) #用0填充


#expandtabs (扩充标签)
# name='wh\thello'
# print(name)
# print(name.expandtabs(1))


# lower(下) ,upper(上)
# name='wh'
# print(name.lower())
# print(name.upper())

# captalize ,swapcase(把大写字母换成小写方法也是转化字符串中字母的大小写),title(标题)
# name='wh'
# print(name.capitalize())
# print(name.swapcase())
# msg='wh say hi'
# print(msg.title())


# isdigt:bytes,unicode
#is 数字系列
#在python3中
# num1=b'4'
# num2=u'4'
# num3='四'
# nim4='IV'
# print(num1.isdigit()) True
# print(num2.isdigit()) True
# print(num3.isdigit()) False
# print(nim4.isdigit()) False


# snumberic (中文数字) unicode(罗马数字)
# bytes类型无isnumberic方法
# print(num2.isnumberi())
# print(num3.isdecimal())
# print(nim4.isdecimal())


#三者不能判断浮点数
# num5='4.3'
# print(num5.isdigit())
# print(num5.isdecimal())
# print(num5.isnumeric())


# ...最常用的是isdigit,可以判断bytes和unicode类型,这也是最常见的数字应用场景
# 如果要判断中文数字或罗马数字,则需要用到isnumeric...

#is 其他
# print('===>')
# name='wh 123'
# print(name.isalnum())
# print(name.istitle())


# print(name.isidentifier())
# print(name.islower())
# print(name.isupper())
# print(name.isspace())
# print(name.istitle())

# while 条件:
# 循环体的代码1
# 循环体的代码2
# 循环体的代码3
# count=0
# while count < 10:
# print(count)
# count+=1

# while True: #死循环
# print('ok')

# while 1: #死循环
# print('ok')



#break:跳出本层循环
# count=0
# while count < 10:
# if count == 5:
# break
# print(count)
# count+=1

#continue:跳出本次循环
#0 1 2 3 7 8 9


# count=0
# while count < 10:
# if count >=4 and count <=6:
# count += 1
# continue
# print(count)
# count+=1


# OLDBOY_AGE=56
# while 1:
# age=input('猜一猜年龄>>: ')
# age=int(age)
#
# if age > OLDBOY_AGE:
# print('太大了')
# elif age < OLDBOY_AGE:
# print('太小了')
# else:
# print('猜对了')
# break



# OLDBOY_AGE=56
# count=1
# while count <= 3:
# age=input('猜一猜年龄>>: ')
# age=int(age)
#
# if age > OLDBOY_AGE:
# print('太大了')
# count+=1
# elif age < OLDBOY_AGE:
# print('太小了')
# count+=1
# else:
# print('猜对了')
# break





OLDBOY_AGE=56
count=1
while True:
if count > 3:
print('您猜的次数超过限制')
break
age=input('猜一猜年龄>>: ')
age=int(age)

if age > OLDBOY_AGE:
print('太大了')
elif age < OLDBOY_AGE:
print('太小了')
else:
print('猜对了')
break
count += 1






# OLDBOY_AGE=56
# while True:
# score = input('>>: ')
# score = int(score)
#
# if score >= 90:
# print('A')
# if score >= 80:
# print('B')
# if score >= 70:
# print('C')
# if score >= 60:
# print('D')
# if score < 60:
# print('E')







OLDBOY_AGE=56
count=0
while True:
if count > 2:
break
age=input('猜一猜年龄>>: ')
age=int(age)
if age > OLDBOY_AGE:
print('太大了')

if age < OLDBOY_AGE:
print('太小了')

if age == OLDBOY_AGE:
print('猜对了')
break
count +=1



# 1 解除name变量对应的值两边的空格,并输出处理结果
# name=' wh '
# b=name.strip()
# print(b)
# 2 判断name变量对应的值是否以'al'开头,并输出结果
# name='alxe'
# if name.startswith(name):
# print(name)
# else:
# print('no')












posted @ 2017-07-18 18:03  Dear坏小子  阅读(172)  评论(0编辑  收藏  举报