while True:a = int(input('摄氏度转换为华氏温度请按1\n华氏温度转化为摄氏温度请按2\n'))if a == 1:celsius = float(input('输入摄氏温度:'))fahreaheit = (celsius + 1.8) + 32 # f = c+9/5+32print('{:.2f}摄氏温度转为华氏温度为{:.2f}'.format(celsius, fahreaheit))elif a == 2:celsius1 = float(input('输入华氏温度:'))fahreaheit1 = (celsius1 - 32) * 5 / 9print('{:.2f}华氏温度转化为摄氏温度为{:.2f}'.format(celsius1, fahreaheit1))else:break;
第二题
import random secret = random.randint(1,20) #print(secret) print('-------猜我新买的玩具多少钱!--------') guess = -1 while guess != secret:a = input('请输入数字:')guess = int(a)if guess > secret:print('输入的数字太大!')elif guess < secret :print('输入的数字太小!')else :print('猜对了!')print('game over,bye!O(∩_∩)O')
第三题
s ='131004199852134451' a=s[:2] b=s[2:4] c=s[4:6] d=s[6:14] e=s[14:16] f=s[-2] g=s[-1] print('省份{}'.format(a)) print('地市{}'.format(b)) print('县区{}'.format(c)) print('出生日期{}'.format(d)) print('顺序码{}'.format(e)) num = int(f) if (num % 2) == 0:print('性别女{}'.format(num)) else:print('性别男{}'.format(num)) print('校验码{}'.format(g))
第四题
for i in range(2,10):print('http://news.gzcc.cn/html/xiaoyuanxinwen/' + str(i) + '.html')