当前位置:网站首页>小测(一)
小测(一)
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来测试):

小结:
这期我们练习了三道小题,希望可以帮助到大家!!!
边栏推荐
- The LAAS protocol elephant of defi 2.0 is the key to revitalizing the development of defi track
- Win11麦克风权限的开启方法
- Golang log programming system
- assert _ Aligns
- 多线程编程
- Nahamcon CTF 2022 babyrev reverse analysis
- Win11大小写提示图标怎么关闭?Win11大小写提示图标的关闭方法
- FPGA_ Initial use process of vivado software_ Ultra detailed
- Longest Substring Without Repeating Characters
- [sql] case expression
猜你喜欢

Image recognition (VI) | activation function

Parallelloopbody in opencv

c语言分层理解(c语言函数)

信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定

Annotation development

Oxycon 2022 network capture frontier conference is about to open!

VOFA+ 串口调试助手
![[steering wheel] tool improvement: common shortcut key set of sublime text 4](/img/51/fe95e95ccd5cd6406f3b49e3bdba3f.png)
[steering wheel] tool improvement: common shortcut key set of sublime text 4

Arthas' dynamic load class (retransform)
![[detailed explanation of key and difficult points of document operation]](/img/f5/99c8cdf09763c66ab5d56cc96e50c7.png)
[detailed explanation of key and difficult points of document operation]
随机推荐
STM32 - PWM learning notes
AMD64 (x86_64) architecture ABI document: medium
The sixth day of the third question of daily Luogu
Software testing post: Ali has three sides. Fortunately, he has made full preparations and has been offered
[translation] safety. Value of sboms
pbootcms上传缩略图尺寸自动缩小变模糊
[steering wheel] tool improvement: common shortcut key set of sublime text 4
(9) Attribute introspection
26 points that must be paid attention to for stability test
STM32——DMA笔记
织梦提示你设定了字段为联动类型如何解决
Wechat official account mutual aid, open white groups, and small white newspaper groups to keep warm
STM32——PWM学习笔记
How about GF Securities? Is it safe to open an account online?
(PC+WAP)织梦模板蔬菜水果类网站
Application of shift distance and hypothesis
What if the test / development programmer gets old? Lingering cruel facts
如何根据登录测试的需求设计测试用例?
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (live template & postfix completion)
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (reconstruction)