第二次作业

1,完整的温度转换程序

while True:
    a = int(input("华氏转为摄氏请按1
摄氏转为华氏请按2
退出请按3
"))
    if a ==1:
        f=float(input("请输入华氏温度:"))
        c = 5 / 9 * (f - 32)
        print('{:.2f}华氏温度转为摄氏温度为:)'.format(c,f))

    if a ==2:
        c = float(input('请输入摄氏温度:'))
        f = (c*1.8)+32
        print('{:.2f}摄氏温度转为华氏温度为:{:.2f}'.format(c,f))

    else:
        break

  

2,猜数字游戏

number=25
guess=17

print('----数字猜谜游戏----
请输入0-100以内的任意整数!
')
while guess !=number:
    guess = int(input('请输入你猜的数字:'))
    if guess == number:
        print('恭喜你,猜对了!')
    elif guess < number:
        print('你猜的数字太小了')
    elif guess > number:
        print('你猜的数字太大了')
    else:
        break

3,解析身份证号、学号不同片段的含义

id='440101199809015027'

a="省份编码:"+id[0:2]
b="地区编码:"+id[2:4]
c="县区编码:"+id[4:6]
d="出生年月日;"+id[6:10]+""+id[10:12]+""+id[12:14]+""
e="户口所在派出所编码:"+id[14:16]
f="性别编码:"+id[16:17]
h="校验码:"+id[17:18]

print('该同学身份信息是:
'+a,b,c,d,e,f,h)

stuid="201606050043"
print("年级"+stuid[0:4])
print("专业"+stuid[4:8])
print("班级"+stuid[8:10])
print("序号"+stuid[10:])

4,字符串的:连接,重复,in判断

a='时间与人生在不断的推波助澜,'
b='我们终究还是会成为温柔的人!'
print(a+b)

c='难得孤寂 !'
print(c*3)

d='English'
print('E' in d)
print('e' in d)

 

5,用for产生一系列网址:

for i in range(0,30,1):  #查询0-30条校园新闻中的奇数网址
    print('http://news.gzcc.cn/html/xiaoyuanxinwen/' + str(i) + '.html')   #方法一
    print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i))    #方法二

 

6,用for循环产生字符串遍历:

str='hello world!'
for i in str:
    print(i)

 

原文地址:https://www.cnblogs.com/hodafu/p/9639638.html