Lesson04

一、Import math

'''
功能:测试math
作者:Sherry
时间:2021.10.23
'''
from math import *
a = 56 % 3
b = -56 % 3
c = 56 % -3
d = -56 % -3
print(pow(2,4) , sqrt(100) , exp(1))
print(a,b,c,d)

二、测试带余除法

'''
作用:测试带余除法
作者:Sherry
日期:2021.10.23
'''
#输如部分
m = int(input('请输入整数:'))
n = int(input('请输入整数:'))
#处理部分
x = int(m / n)
z = m % n
#输出部分
print("{} ÷ {} = {} ... {}".format(m, n, x, z))

三、等差函数测试

i = 2
while i <= 100:
    print(i,end='\n')
    i += 2

效果图:

四、成绩处理(保留两位小数)

'''
功能:成绩处理
作者:Sherry
日期:2021.10.23
'''

#输入部分
sth = float(input("请输入sth成绩:"))
sql = float(input("请输入sql成绩:"))
python  = float(input("请输入python成绩:"))

#处理部分
difference = python +sql
average = (sth + sql +python) / 3

#输出部分
print("sth","sql",'python',sep='\t')
print(sth,sql,python,sep="\t")
print('python与sql成绩和为{}'.format(difference))
print('三门课的平均成绩:%.2f' %average)

效果图:

 五、打印小票(允许三次出错-功能还为完善,在测试时还有一个错误正在修改中)

# -*- coding: utf-8 -*-
"""
功能:打印购物小票
作者:华卫
添加:Sherry
日期:2020年11月7日
"""

# 输入部分
discount = 0.8 # 8折优惠
price1 = float(input("输入运动衫单价:"))
amount1 = int(input('输入运动衫购买'
                    '数量:'))
price2 = float(input("输入网球鞋单价:"))
amount2 = int(input('输入网球鞋购买数量:'))
price3 = float(input("输入网球拍单价:"))
amount3 = int(input('输入网球拍购买数量:'))
payment = float(input('顾客实际交费:'))

# 处理部分
money = (price1 * amount1 + price2 * amount2 + price3 * amount3) * discount # 计算购物金额
#循环三次
count = 0
while count <= 2:
    count += 1
    if payment >= money:
        change = payment - money;  # 计算找钱
        points = int(money // 33);  # 计算购物积分

        # 整体输出
        print('***************消费单**************')
        print('%-8s%-6s%-6s%-6s' % ('购买物品', '单价', '数量', '金额'))
        print('%-8s%-8.2f%-8d%-8.2f' % ('运动衫', price1, amount1, price1 * amount1))
        print('%-8s%-8.2f%-8d%-8.2f' % ('网球鞋', price2, amount2, price2 * amount2))
        print('%-8s%-8.2f%-8d%-8.2f' % ('网球拍', price3, amount3, price3 * amount3))
        print('***********************************')
        print('折扣:{}折'.format(int(discount * 10)))
        print('消费总金额:¥{}'.format(round(money, 2)))
        print('实际交费:¥{}'.format(payment))
        print('找钱:¥{}'.format(round(change, 2)))
        print('本次购物所获得的积分:{}'.format(points))
    else:
        diff = money - payment
        print("温馨提示:钱没给够还差{}元".format(diff))
        payment = float(input('顾客实际交费:'))
        continue
        break
else:
    print('请重新输入!')





效果图:

 六、数学公式计算

'''
功能:公式计算
作者:Sherry
日期:2021.10.23
'''
from math import sqrt

a = float(input("a = "))
b = float(input('b = '))
c = float(input('c = '))

delta = b**2 - 4 * a * c
if delta >= 0:
    x1 = (-b + sqrt(delta)) / (2 * a)
    x2 = (-b + sqrt(delta)) / (2 * a)
    print('x1 = {}\n x2 = {}'.format(x1 , x2))
else:
    print('此方程没有实数解!')

效果图:

成功:

 失败:

七、计算利息

'''
功能:计算利息
作者:Sherry
时间:2021.10.23
'''
import numpy as np
import matplotlib.pyplot as plt
pv = 1
for n in range(1 , 366):
    fv = pv * (1 + 1/n)**n
    print("fv_{} = {}" .format(n, fv))
x = np.linspace(-20,20,100)
y = np.exp(x)
plt.plot(x,y,color='red')


效果图(未绘图):

 八、计算闰年

'''
功能:计算闰年
作者:Sherry
时间:2021.10.23
'''
year = int(input('year = '))

if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
    print('{}是闰年。'.format(year))
else:
    print('{}是平年。'.format(year))

九、Homework

'''
功能:计算三角形面积
作者:Sherry
时间:2021.10.24
'''
#键入值以及定义值
from math import sqrt
a = float(input('请输入边长a的值:'))
b = float(input('请输入边长b的值:'))
c = float(input('请输入边长c的值:'))

#判断是否构成三角形以及输出值
if a + b > c and a + c >b and b + c >a:
    p = (a + b + c) / 2
    area = sqrt(p * (p - a) * (p - b) * (p - c))
    print("area = %.2f" %area)
else:
    print("{}、{}、与{},无法构成三角形!".format(a, b, c))


这是第4次课

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫腻余腥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值