zoukankan      html  css  js  c++  java
  • python基础:条件循环字符串

    while True:
        a = int(input('摄氏度转换为华氏温度请按1
    华氏温度转化为摄氏温度请按2
    '))
    
        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')

  • 相关阅读:
    【SpringBoot系列】邮件发送
    【问题】InteliJ IDEA生成可执行jar运行提示没有主清单属性
    【设计模式】单例设计模式
    【C3P0】C3P0
    【JDBC】JDBC学习(一)
    react hook 防抖
    主线程 宏任务 微任务
    vue 2.0 渲染dom过程
    源码阅读笔记,杂乱
    vue 3.0 响应式原理
  • 原文地址:https://www.cnblogs.com/dalin-lyl/p/9639405.html
Copyright © 2011-2022 走看看