python基础:条件循环字符串

2021-07-01 02:04

阅读:565

标签:while   分享   color   soscw   技术分享   ESS   条件   字符   出生日期   

while True:
    a = int(input(‘摄氏度转换为华氏温度请按1\n华氏温度转化为摄氏温度请按2\n‘))

    if a == 1:
        celsius = float(input(‘输入摄氏温度:‘))
        fahreaheit = (celsius + 1.8) + 32  # f = c+9/5+32
        print(‘{:.2f}摄氏温度转为华氏温度为{:.2f}‘.format(celsius, fahreaheit))
    elif a == 2:
        celsius1 = float(input(‘输入华氏温度:‘))
        fahreaheit1 = (celsius1 - 32) * 5 / 9
        print(‘{:.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‘)

技术分享图片

python基础:条件循环字符串

标签:while   分享   color   soscw   技术分享   ESS   条件   字符   出生日期   

原文地址:https://www.cnblogs.com/dalin-lyl/p/9639405.html


评论


亲,登录后才可以留言!