homework02

#1.解一元二次方程组
“”"
import math
def root():
a=float(input(‘请输入a的值:’))
b=float(input(‘请输入b的值:’))
c=float(input(‘请输入c的值:’))
d=bb-4ac
r=(-1
b+(math.sqrt(d)))/2a
r1=(-1
b-(math.sqrt(d)))/2*a
if d>0:
print(‘the roots are %.6f and %.6f’%(r,r1))
elif d==0:
print(‘the root is %.1f’%r)
else:
print(‘the equation has no real roots’)
root()
“”"

#2.游戏:学习加法
“”"
import random
num=random.randint(1,100)
num1=random.randint(1,100)
print(num+num1)

def sum():
sum=num+num1
a=int(input(‘请输入两个数的和:’))
if sum==a:
print(‘True’)
else:
print(‘False’)

sum()
“”"

#3.找未来数据

def week():
today = int(input(‘Enter todays day:’))
count = int(input(‘Enter the mumber of days elapsed since today:’))
fd=count%7
b=today+fd
c=b%7
print(‘Today is 星期%d and the future day is 星期%d’%(today,c))

week()

#4.输入三个整数,升序排列
“”"
q = [59,21,33]
q.sort()
print(q)
“”"
#5.金融方面:比较价钱
“”"
def contrast(money1,weight1,money2,weight2):
num1 = money1 / weight1
num2 = money2 / weight2
if num1 > num2:
print(“第二种大米价钱更好”)
elif num1 < num2:
print(“第一种大米价钱更好”)
else:
print(“两种大米价格相同”)

def Star():
money1 = float(input(“请输入第一种大米的价钱:”))
weight1 = float(input(“请输入第一种大米的重量:”))
money2 = float(input(“请输入第二种大米的价钱:”))
weight2 = float(input(“请输入第二种大米的重量:”))
contrast(money1,weight1,money2,weight2)

Star()
“”"
#6.找出一个月中的天数
“”"
def day(year,month):
days = [‘null’,‘31’,‘29’,‘31’,‘30’,‘31’,‘30’,‘31’,‘31’,‘30’,‘31’,‘30’,‘31’]
sum = days[month]
print("%d年%d月份有%s天"%(year,month,sum))

def Start():
year = int(input(“请输入年份:”))
month = int(input(“请输入月份:”))
day(year,month)

Start()
“”"
#7.游戏:头或尾
“”"
import random
def pan(pao,caice):
print(“硬币弹起方向%d”%pao)
if pao == caice:
print(“恭喜你,答对啦!”)
else:
print(“很遗憾,答错了”)

def Start():
pao = random.randint(1,2)
caice= int(input(“你猜测的结果是[1.正面 2.反面]:”))
pan(pao,caice)

Start()
“”"
#8石头剪刀布
“”"
def main():
import random
user = int(input(“剪刀(0), 石头(1), 布(2):”))
comp = random.randint(0,2)
print(comp)
if (user1 and comp0) or (user0 and comp2) or (user==2 and comp 1):
print(“你赢了”)
elif user
comp:
print(‘平局’)
else:
print(“你输了”)
def Start():
main()
Start()
“”"

#9.一周的星期几
“”"
def main():
year = int(input(‘输入哪一年:’))
q = int(input(‘输入月份:’))
d = int(input(‘输入第几天:’))
a = [‘周六’,‘周日’,‘周一’,‘周二’,‘周三’,‘周四’,‘周五’]
if q == 1:
q = 13
year = year - 1
if q ==2:
q = 14
year = year - 1
h = int(d+((26*(q+1))//10)+(year%100)+((year%100)/4)+((year//100)/4)+5*year//100)%7
day = a[h]
print(‘那一天是一周中的:%s’ %day)
def Start():
main()
Start()
“”"

#10.选一张牌
“”"
def chou():
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)
def Start():
q = input(“是否决定抽牌y/n:”)
if q == ‘y’:
chou()
else:
pass
Start()
“”"

#11.回文数
“”"
def main():
a1 = int(input(‘请输入一个正整数: ‘))
b = a1
a2 = 0
while b > 0:
a2 *= 10
a2 += b % 10
b //= 10
if a1 == a2:
print(’%d是回文数’ % a1)
else:
print(’%d不是回文数’ % a1)
def star():
main()
star()
“”"

#12.三角形
“”"
def sanjiao():
a = float(input(“请输入第一条边长”))
b = float(input(“请输入第二条边长”))
c = float(input(“请输入第三条边长”))
if a+b>c and a+c>b and b+c>a:
L = a+b+c
print(“其周长为”,L)
else:
print(“不是三角形三条边”)
def Star():
sanjiao()
Star()

你可能感兴趣的:(homework02)