条件循环字符串


## while条件语句循环

while True :


a = int(input("摄氏温度转换为华氏温度请按1\n华氏温度转换为摄氏温度请按2\n"))

if a == 1:
sheshi = float(input("请输入摄氏温度:"))
huashi = (sheshi * 1.8)+ 32
print('{:.2f}摄氏温度转换为华氏温度为{:.2f}\n'.format(sheshi,huashi))
elif a == 2:
huashi = float(input("请输入华氏温度:"))
sheshi = 5 / 9 * (huashi - 32)
print('{:.2f}华氏温度转换为摄氏温度为:{:.2f}\n'.format(huashi,sheshi))
else:
break
结果:

##数字猜谜游戏

number = 9
guess = 5
print("数字猜谜游戏!")
while guess != number:
guess = int(input("请输入你猜的数字:\n"))
if guess == number :
print("恭喜,你猜对了!")
elif guess <number:
print("你猜的数字小了")
elif guess > number:
print("你猜的数字大了")

结果:


##身份证的解析

s = '12345678910102232232'
print('省份:{}.年龄:{}.性别:{}.'.format(s[4:6],s[8:10],s[-2]))

结果:

##网页浏览
#url = "http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0909/"+"9896"+".html"
for i in range(1,15):
print('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+'.html')

结果:

 

猜你喜欢

转载自www.cnblogs.com/huang201606050002/p/9618177.html
今日推荐