Skip to content

Instantly share code, notes, and snippets.

@ranlix
ranlix / is_int.py
Last active December 26, 2015 12:38
用于测试手机屏幕在播放某些分辨率的视频的时候的补偿值: 32*x + 2(or 4 or 8 or 16 or 32) = y, 在y输入任意正整数的时候,保证x为有且仅有一个正整数的值
# -*- coding=utf-8 -*-
def is_int():
inputNum = int(input("Please input a number: "))
#生成补偿值的列表
offset_list = range(1,6)
#生成 inputNum-补偿值 列表
new_list = [(inputNum - 2**i)%32 for i in offset_list]
#判断 inputNum-补偿值是不是32的倍数
if new_list.count(0) == 1:
# Rock-paper-scissors-lizard-Spock template
import random
# The key idea of this program is to equate the strings
# "rock", "paper", "scissors", "lizard", "Spock" to numbers
# as follows:
#
# 0 - rock
# 1 - Spock
# 2 - paper
@ranlix
ranlix / SMTP.py
Last active December 24, 2015 05:19
用smtplib来登录连接邮箱,发送测试邮件到目标邮件
# -*- coding:utf-8 -*-
import smtplib
username = "*******@163.com"
password = "*********"
smtp = smtplib.SMTP() #继承SMTP()的属性
smtp.connect("smtp.163.com","25") #连接服务器和端口
mail_text = """
From: *******@163.com\r\n
Python内置函数清单
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。
Python内置(built-in)函数随着python解释器的运行而创建。在Python的程序中,你可以随时调用这些函数,不需要定义。
最常见的内置函数是:
print("Hello World!")
Python补充01 序列的方法
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。谢谢!
在快速教程中,我们了解了最基本的序列(sequence)。回忆一下,序列包含有定值表(tuple)和表(list)。
此外,字符串(string)是一种特殊的定值表。表的元素可以更改,定值表一旦建立,其元素不可更改。
@ranlix
ranlix / gist:5983386
Last active December 19, 2015 16:19
page61
# -*- conding:utf-8 -*-
import math
import calendar
#1.a)
math.abs(-4.3)
#1.b)进一法是嘛?ceil?
math.ceil(math.sin(34.5))
#2.a)
# coding=utf-8
import time
from datetime import datetime
from douban_client import DoubanClient
LAST_MINUTE = 59 # when it is the last mintue in an hour,the minute is (60-1)
MINUTE_SECONDS = 60 # one minute has 60s
API_KEY = 'your api key'
API_SECRET = 'your api secret'
SCOPE = 'douban_basic_common,shuo_basic_r,shuo_basic_w'
@ranlix
ranlix / TheBigBen.py
Last active December 17, 2015 09:08
Created by Alex Li; Bell us when it's the whole point
# coding=gbk
import time
from datetime import datetime
LAST_MINUTE = 59 #when it is the last mintue in an hour,the minute is (60-1)
MINUTE_SECONDS = 60#one minute has 60s
def main():
'''This is a main function to print bell when time is the whole point.'''