学python的第二天

课上笔记重点

evla是可连续输入多个整数,每个整数中间用逗号隔开

import numpy as np
renji = np.random.choice(['石头','剪刀',''])#在这个选项中随机调出选项
raise KeyError('Only choos [+,-,*,/]')#抛出错误
yanzhengma = random.randrange(1000,9999)#随机产生给予范围之内的随机数字。
shuzu=['星期一,星期二,星期三,星期四,星期五,星期六,星期日']#数组

课后练习:

import math
a,b,c = eval(input("请输入三个数"))
i=3
if b*b-4*a*c>0:
    r1=(-b+(b*b-4*a*c)**0.5)/2*a
    r2=(-b-(b*b-4*a*c)**0.5)/2*a
    print("方程解为{0}和{1}".format("%.6f"%r1,"%.5f"%r2))
elif b*b-4*a*c==0:
    r1=(-b+(b*b-4*a*c)**0.5)/2*a
    r2=(-b-(b*b-4*a*c)**0.5)/2*a
    print("方程解为{0}和{1}".format("%.6f"%r1,"%.5f"%r2))
else:
    print('方程没有实根')
    

import random
import math
z1 = random.randrange(0,100)
z2 = random.randrange(0,100)
print('两个数分别为{0}和{1}'.format(z1,z2))
zhengshu = input('请输入一个整数')
if  zhengshu==z1+z2:
    print('你输入的是正确的')
else:
    print('你是错误的')

import math
shuzu=['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
a = int(input('请输入一个数字'))
b = int(input('请输入再过几天'))
c=(a+b%7)%7
print('今天是{}再过{}天是{}'.format(shuzu[a],b,shuzu[c]))

a,b,c = eval(input('请输入三个整数'))
if a>b>c:
    print(a,b,c)
elif a>c>b:
    print(a,c,b)   
elif b>a>c:
    print(b,a,c)
elif b>c>a:
    print(b,c,a)
elif c>a>b:
    print(c,a,b)
elif c>b>a:
    print(c,b,a)

jiaqian1,zgongliang1 = eval(input('请输入大米的价钱和重量'))
jiaqian2,zgongliang2 = eval(input('请输入大米的价钱和重量'))
if jiaqian1/zgongliang1>jiaqian2/zgongliang2:
    print('jiaqian2的大米更好')
else:
    print('jiaqian的大米更好')

a= ['13月','1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
nian,yue = eval(input('请输入年和月'))
if nian%4==0 and nian%100 !=0 and yue==2 or nian%400==0:
    print('{}年{}有29天'.format(nian,a[yue]))
elif nian%4==0 and nian%100 !=0 or nian%400==0 and yue != 2 and yue ==1 or 3 or 5 or 7 or 8 or 10 or 12:
    print('{}年{}有31天'.format(nian,a[yue]))
elif nian%4==0 and nian%100 !=0 or nian%400==0 and yue != 2 and yue ==4 or 6 or 9 or 11:
    print('{}年{}有30天'.format(nian,a[yue]))
elif yue == 2 and yue !=1 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 or 11 or 12:
    print('{}年{}有28天'.format(nian,a[yue]))

import numpy as np
a = np.random.choice(['正面','反面'])
b = input('输入正面或者反面:')
if b==a:
    print('正确')
else:
    print('错误')

import numpy as np 
res = np.random.choice(['0','1','2'])
my = input("0,1,2:")
if my in '0,1,2':
    if my == "0":
        if res == "0":
            print("over")
        elif res == "1":
            print("res win")
        elif res == "2": 
             print("my win")  
    if  my == "1":
        if res == "0":
            print("my win")
        elif res == "1":
            print("over")
        elif res == "2": 
             print("res win")
    if my =="2":
        if res == "0":
            print("res win")
        elif res == "1":
            print("my win")
        elif res == "2": 
             print("over")
print("电脑出:",res)
print("我出:",my)

import math
year,m,q=map(int,input('请输入年月日【逗号隔开】').split(','))
j=math.floor(year/100)
k=year%100
h=(q+math.floor(26*(m+1)/10)+k+math.floor(k/4)+math.floor(j/4)+5*j)%7
week=['星期六','星期日','星期一','星期二','星期三','星期四','星期五']
print('Day of the week is %s'%week[h])

import numpy as np 
res = np.random.choice(['A','2','3','4','5','6','7','8','9','10','j','q','k'])
my = np.random.choice(['梅花','红桃','方块','黑桃'])
if my in '梅花,红桃,方块,黑桃':
    if my == "梅花":
        print(my+res)
    if my == "红桃":
        print(my+res)
    if my == "方块":
        print(my+res)
    if my == "黑桃":
        print(my+res)

a,b,c= eval(input('请输入一个三位数'))
if a==c:
    print('{0}{1}{2}这个回文数为'.format(a,b,c))
else:
    print('{0}{1}{2}不是回文数'.format(a,b,c))

a,b,c = eval(input('请输入三个正数'))
if a+b>c and a+c>b and b+c>a:
    x=a+b+c
    print('合法周长是{}'.format(x))
else:
    print('非法')

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/zrxuexi/p/11279217.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值