Python 4- more operations
来源:互联网 发布:嵌入式软件面试题 编辑:程序博客网 时间:2024/06/06 02:41
# Remainder - modular arithmetic
# systematically restrict computation to a range
# long division - divide by a number, we get a quotient plus a remainder
# quotient is integer division //, the remainder is % (Docs)
# problem - get the ones digit of a number
num = 49
tens = num // 10 #除号在python里面是//
ones = num % 10 #求余数
print tens, ones
print 10 * tens + ones, num
# application - 24 hour clock
# http://en.wikipedia.org/wiki/24-hour_clock
hour = 20
shift = 8
print (hour + shift) % 24
# application - screen wraparound
# Spaceship from week seven
width = 800
position = 797
move = 5
position = (position + move) % width
print position
# Data conversion operations
# convert an integer into string - str
# convert an hour into 24-hour format "03:00", always print leading zero
hour = 3
ones = hour % 10
tens = hour // 10
print tens, ones, ":00"
print str(tens), str(ones), ":00"
print str(tens) + str(ones) + ":00"
# convert a string into numbers using int and float
# Python modules - extra functions implemented outside basic Python
import simplegui # access to drawing operations for interactive applications
import math # access to standard math functions, e.g; trig
import random # functions to generate random numbers
# look in Docs for useful functions
print math.pi
0 0
- Python 4- more operations
- SQLZOO(More JOIN operations)Writeup
- More about the Operations of string
- sqlzoo练习答案--More JOIN operations
- sqlzoo练习答案--More JOIN operations
- More Python
- Operations
- Python: Shallow and deep copy operations
- The Python Tutorial 4——More Control Flow Tools
- spark-streaming-[4]-Window Operations
- Beginning Python - Chapter6 : More Abstraction
- Python解决SEND MORE MONEY
- Elementary Matrix Operations In Python https://github.com/vibrationtoolbox/vibration_toolbox
- The Python Tutorial 3.2-4 More Control Flow Tools(深入控制流)
- OpenShare实现(4): more
- 【4】More About Triggers
- more
- more
- VC Win32 读取 磁盘MBR 和 EBR扩展分区 数据
- 【译】使用Rails 4.2+ 测试异步邮件系统
- CFHTTP使用SSL很慢的解决方法
- 今天是我第一次开通本博客 自己爱好学习破解软件,OEM软件。易语言做软件等等,
- MAC MySQL乱码问题解决路径
- Python 4- more operations
- i春秋:通过案例学安全—再现杰奇网站漏洞环境
- i春秋:警惕您站上的MIME类型绕过漏洞
- i春秋:警惕您站上的文件扩展名绕过漏洞
- 【PagerAdapter】Fragment的陷阱
- i春秋:警惕您站上的文件内容检测绕过类上传漏洞
- i春秋:警惕您站上的空字节截断目录路径检测绕过类上传漏洞
- i春秋:警惕IIS6.0站上的解析缺陷绕过上传漏洞
- i春秋:警惕IIS6.0站上的目录路径检测解析绕过上传漏洞