HNU 实训4.1(部分)~4.2

#Student Start
def f(x):
    return x**3-10*x**2-25*x+250
def fp(x):
    return 3*x**2-20*x-25
x0=eval(input())
x1=x0-f(x0)/fp(x0)
while abs(x1-x0)>1e-6:
    x0=x1
    x1=x0-f(x0)/fp(x0)
print('x={:.6f}'.format(x1))

#student End

 

### 百钱百鸡 ###
c=0
for i in range(21):
    for j in range(34):
        if i*5+j*3+(100-i-j)//3==100 and (100-i-j)%3==0:
            c+=1
            print('鸡翁的数量是{} 鸡母的数量是{} 鸡雏的数量是{}'.format(i,j,100-i-j))
print('共有4种买法')

# -*- coding: utf-8 -*-
"""
Created on Thu Dec 10 08:19:29 2020
鸡兔同笼
@author: Admin
"""
print("请输入总的头数")
heads = int(input())
print("请输入总的脚数")
legs = int(input())
### Begin ###
if legs<0 or heads<0 or heads>legs:
    print('{}只动物{}条腿的情况无解'.format(heads,legs))
else:
    for i in range(heads+1):
        for j in range(heads+1):
            if i+j==heads and i*2+j*4==legs:
                print('鸡有{}只 兔有{}只'.format(i,j))


### End ###
def guess(x,low,high):
    '''AI猜数函数,猜测x的值
    low:数据x所在范围的下界
    high:数据x所在范围的上界
    返回猜测的次数
    '''
    ### Begin ###
    c=0
    while high>=low:
        mid=(high+low)//2
        if mid==x:
            return c
        elif mid>x:
            print('大了')
            high=mid-1
        elif mid<x:
            print('小了')
            low=mid+1
        c+=1

    ### End ###

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值