当前位置:网站首页>小测(一)
小测(一)
2022-07-26 03:02:00 【程序员昊子】
目录
本期要点:
前几期的话我们学到了许多知识,那么这期我们就来检验检验,这里我准备了三道小题,只要前面仔细看就可以做出来,屏幕目前的你来试试吧!!!
本期内容:
第一题:
题目:今天是2022年7月25日,那么我们将它写为时间整数就是:2022725,这里我们要利用分别计算取出它的年、月、日
思路:抓重点:2022725 利用计算,那么计算是什么呢?那就是加法、减法、乘法、除法、整除、取余其中的几种来写这道题
我相信你一定有了自己的一个答案,那么接下来咱们来解一下:
源代码:
Date = 2022725
Year = Date // 1000 # 通过整除来获取到2022
Month = Date // 100 %10 # 通过整除和取余来获取到7
Day = Date % 100 # 通过取余来获取到25
# 打印结果:
print(Year)
print(Month)
print(Day)打印结果:

第二题:
题目:将Hello、Python这两个单词拼接起来。
思路: 依旧是抓重点:“单词”确定了这是字符串类型 “拼接”也就是放到一起 所以:这道题的考点为字符串的拼接。
我相信你一定有了自己的一个答案,那么接下来咱们来解一下:
源代码:
str1 = 'Hello' # 先把第一个赋值
str2 = 'Python' # 再把第二个赋值
# 第一种:
# 字符串格式化拼接
print('%s %s' % (str1,str2))
# 第二种:
# join方法拼接
print(' '.join([str1,str2]))
# 第三种:
# format方法拼接
print('{} {}'.format(str1,str2))
# 第四种:
# format简写法拼接
print(f'{str1} {str2}')打印结果:

第三题:
题目:让用户提供半径,然后计算出对应圆的周长和面积(结尾保留两位小数)
思路:还是抓重点:用户提供,用到我们的input内置函数 并且需要借助数学模块获取圆周率 了解圆周长和面积的公式 保留两位小数,可以用字符串的格式化和高精度模块
我相信你一定有了自己的一个答案,那么接下来咱们来解一下:
源代码:
# 导入数学模块
import math
# 导入高精度模块
import decimal
# 让用户提供圆的半径
r = int(input("请输入圆的半径:"))
# 获取圆周率
pi = math.pi
# 周长公式(高精度)
C = decimal.Decimal(r) * decimal.Decimal(2) * decimal.Decimal(pi)
# 面积公式(高精度)
S = decimal.Decimal(r) ** decimal.Decimal(2) * decimal.Decimal(pi)
# 打印周长并保留两位小数
print('%.2f' % C)
# 打印面积并保留两位小数
print('%.2f' % S)打印结果(以半径为5来测试):

小结:
这期我们练习了三道小题,希望可以帮助到大家!!!
边栏推荐
- Influence of middle tap change on ZVS oscillation circuit
- FPGA_ Initial use process of vivado software_ Ultra detailed
- VOFA+ 串口调试助手
- STM32——DMA笔记
- Unity快速搭建城市场景
- 如何有效的去防止别人穿该网站首页快照
- 中国信通院陈屹力:降本增效是企业云原生应用的最大价值
- 【C进阶】深入探索数据的存储(深度剖析+典例解读)
- The source of everything, the choice of code branching strategy
- Nahamcon CTF 2022 babyrev reverse analysis
猜你喜欢

Case: using kept+haproxy to build a Web Cluster

Extended Physics-InformedNeural Networks论文详解

Masscode is an excellent open source code fragment manager
![[sql] case expression](/img/05/1bbb0b5099443f7ce5f5511703477e.png)
[sql] case expression

Swin Transformer【Backbone】

DFS Niuke maze problem

重装Win7系统如何进行?
![[C language] deeply understand integer lifting and arithmetic conversion](/img/5c/21d0df424c034721c64b0653edc483.png)
[C language] deeply understand integer lifting and arithmetic conversion

OxyCon 2022 网络抓取前沿大会即将开启!

Annotation development management third-party beans
随机推荐
Win11更改磁盘驱动器号的方法
Win11麦克风权限的开启方法
1. Software testing ----- the basic concept of software testing
软件测试岗:阿里三面,幸好做足了准备,已拿offer
如何根据登录测试的需求设计测试用例?
Method of manually cloning virtual machine in esxi6.7
Shardingsphere data slicing
基础知识-网络与服务器
STM——EXTI外部中断学习笔记
Extended Physics-InformedNeural Networks论文详解
Usage of '...' in golang
信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定
[steering wheel] tool improvement: common shortcut key set of sublime text 4
Jenkins' study notes are detailed
多线程编程
规范自己debug的流程
Image recognition (VII) | what is the pooling layer? What's the effect?
(PC+WAP)织梦模板蔬菜水果类网站
Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
从各大APP年度报告看用户画像——标签,比你更懂你自己