• 学习Python的第二天


    1、今天学习了循环语句

    2、以下是一些小程序

    import math
    a,b,c=map(float,input('Enter a,b,c:').split(','))
    root_=(b*b)-(4*a*c)
    if root_>0:
        root_1=(-b+math.sqrt(b*b-4*a*c))/2*a
        root_2=(-b-math.sqrt(b*b-4*a*c))/2*a
        print('The roots are %f and %f'%(root_1,root_2))
    elif root_==0:
        root_1=(-b+math.sqrt(b*b-4*a*c))/2*a
        print('The root is %f'%root_1)
    else:
        print('The equation has no real roots')

     import random
    num1=random.randint(0,100)
    num2=random.randint(0,100)
    print(num1,num2)

    sum=num1+num2

    sum_=int(input('请输入两个数的和:'))
    if sum_==sum:
        print('正确')
    else:
        print('错误')

    today=int(input('Enter today:'))
    day_num=int(input('Enter the number of days elapsed since today:'))
    week=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
    futureweek=today+day_num
    now=0
    now=futureweek%7
    print("Today is %s and the future day is %s"%(week[today],week[now]))

    num1,num2,num3=map(int,input('请输入三个整数:').split(','))
    x=[num1,num2,num3]
    x.sort()
    print(x)

    weight_1,price_1=map(float,input('Enter weight and price for package1:').split(','))

    weight_2,price_2=map(float,input('Enter weight and price for package2:').split(','))
    vaule_1=weight_1/price_1
    vaule_2=weight_2/price_2

    if vaule_1>vaule_2:
        print('Package1 has the better price')
    elif vaule_1==vaule_2:
        print('same')
    else:
        print('Package2 has the better price')

    year,month=map(int,input('输入年份和月份:').split(','))

    if (year % 4==0 and year %100 !=0 )or (year%400==0):
        day_=int('29')
    else:
        day_=int('28')
        
    if month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month==12:
        day=int('31')
    elif month==4 or month==6 or month==9 or month==11:
        day=int('30')
    else :
        day=day_

    print('%d 年%d月份有%d天'%(year,month,day))

    import numpy as np
    computer=np.random.choice(['正面','反面'])

    hum=input('请输入你的选择:')
    print(computer)
    if computer == hum:
        print('正确')
    else:
        print('错误')

    import random

    s=int(input('剪刀(0), 石头(1), 布(2): '))
    i=random.randint(0,2)

    print(i)
    if (s == 0 and i == 2) or (s == 1 and i == 0) or (s == 2 and i == 1):
        print('You won.')
    elif s==i:
        print('ping')
    else:
        print('Loser')

    y=int(input('Enter year:(e.g.,2008):'))
    m=int(input('Enter month:1-12:'))
    d=int(input('Enter the day of the month:1-31:'))
    a=['Saturday','Sunday','Monday','Tuesday','Wednesday','Thurday','Firday']
    if m==1:
        m=13
        y=y-1
    if m==2:
        m=14
        y=y-1
    h=int(d + ((26 * (m + 1) ) // 10) + (y % 100) + ((y % 100) / 4) + ((y // 100) / 4) + 5 * y // 100) % 7
    o=a[h]
    print('Day of the week is %s'%o)

    import numpy as np
    daxiao=np.random.choice(['Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King'])
    huase=np.random.choice(['梅花','红桃','方块','黑桃'])
    print('你选择的牌是',huase,daxiao)

    num=int(input('输入一个三位整数:'))
    bai=num//100
    shi=num//10%10
    ge=num%10
    if bai==ge:
        print('是回文数!')
    else:
        print('不是回文数')

    a,b,c=map(float,input('Enter three edges:').split(','))
    if (a+b)>c and (a+c)>b and (b+c)>a:
        print('The perimeter is %.0f'%(a+b+c))
    else:
        print('不合法')

  • 相关阅读:
    centos 7.0 yum 分开安装 LAMP 环境 +zabbix3.4环境
    互联网产品接入支付功能如何测试?
    python实现:将文本文件分割成多个小文本文件(php也可实现)
    『危机领导力』告诉我们如何带好团队
    Fiddler显示服务器IP的方法
    Google PageSpeed Tools 性能测试分析
    写给浮躁的测试工程师一封信
    数据库事务和锁
    测试工作中ADB命令实战
    git使用基础
  • 原文地址:https://www.cnblogs.com/TheNeverLemon/p/11280378.html
Copyright © 2020-2023  润新知