惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - bela liu

生成PDF文档,并在PDF文档结尾加印章 EF CodeFirst 学习 1 - 用fluent API设置元数据, silverlight: 关于dataform的commit silverlight:datagrid滚动 win7下chm打不开 MS DTC 无法正确处理DC升级/降级事件。MS DTC 将继续运行并使用现有的安全设置。 远程桌面如果超出最大连接数, 使用命令行mstsc /console登录即可。 windows server 2008 安装live mail windows server 2008 安装 MSN Help: DCOM中设定"launch permission"的问题 Qt 学习(1) 使用firefox的一个小技巧 - bela liu - 博客园 现有一车(千里马)过年从苏州回赣榆,15号或者17号出发,21号,23号或者25号返程。 在Oracle中申明与某个字段类型相同的变量 在ReportViewer中使用超链接(HyperLink) 未解之Bug (1) : 必须放在具有 runat=server 的窗体标记内 在window.showModelessDialog打开的窗体中调用原窗体的alert会使IE死掉。 [转]面向对象与数据模型 在模式窗体中提交而不打开新窗体
几道Python的习题
bela liu · 2006-11-25 · via 博客园 - bela liu

搞着玩。

1。allVowels (inString)
Returns True if all characters in inString are vowels, False otherwise. Note that an empty
string is trivially all vowels.
要求是当输入的inString里的字母都是元音的话, 执行程序后显示TRUE ,不都是的话显示FALSE。
列子:
allVowels (inString)
>>> allVowels("a")
True
>>> allVowels("a eoa")
False
>>> allVowels("iaiaa")
True

 1 #!/usr/bin/python
 2 # Filename: function1.py
 3 
 4 def allVowels( inString ) :
 5     vowels = "aeiouAEIOU";
 6     ret = True;
 7     for c in inString:
 8         if c not in vowels :
 9             ret = False;
10             break;
11     return ret;
12 
13 
14 print allVowels("a")
15 print allVowels("a eoa")
16 print allVowels("iaiaa")

 
2。average(integerList)
Returns the mean value of the integers stored in the list integerList.
要求显示输入的一组数字的平均数
列子:
average(integerList)
>>> average([5,7,8])
6.666666666666667
>>> average([10])
10.0
>>> average([1,2,3])
2.0

 1 #!/usr/bin/python
 2 # Filename: 2.py
 3 
 4 def average( integerList ) :
 5         sum = 0
 6         for i in integerList :
 7             sum += i
 8         num = len( integerList )
 9         if num > 0 :
10             return sum / num 
11         else :
12             return None
13 
14 
15 print average([5,7,8])
16 print average([10])
17 print average([1,2,3])
18 print average( [] )
19 

3。toBinary (integerValue)
Returns string consisting of the binary representation of integerValue.
要求把输入的10进制数字转为2进制
列子:
toBinary (integerValue)
>>> toBinary(17)
'10001'
>>> toBinary(6)
'110'
>>> toBinary(0)
'0'
>>> toBinary(1012)
'1111110100'

 1 #!/usr/bin/python
 2 # Filename: 3.py
 3 
 4 def toBinary (integerValue) :    
 5     str = ""
 6     tryit = True
 7     while tryit :
 8         i = integerValue % 2;
 9         if (i == 0) :
10             str = "0" + str;
11         else:
12             str = "1" + str;
13         integerValue = integerValue // 2
14         tryit = integerValue > 0;
15     return str;
16 
17 print toBinary(17)
18 print toBinary(6)
19 print toBinary(0)
20 print toBinary(1012)

4。complexPalindrome(inString)
Returns True if inString is a complex palindrome, False if it it not. A complex palindrome is
a string that is the same forwards and backwards, ignoring spaces and capitalization.
要求如果输入的字母是对称的话 (大小写和空格忽略)显示TRUE, 不是的话显示FALSE。
列子:
complexPalindrome(inString)
>>> complexPalindrome("Aha")
True
>>> complexPalindrome("AHA")
True
>>> complexPalindrome("Race car")
True
>>> complexPalindrome("a")
True

 1 #!/usr/bin/python
 2 # Filename: 4.py
 3 
 4 def complexPalindrome(inString) :    
 5     i=0
 6     j=-1
 7     L = len(inString)
 8     while i - j < L :
 9         if (inString[i] == " ") :
10             i += 1
11             continue
12         if (inString[j] == " ") :
13             j -= 1
14             continue
15         if inString[i].lower() != inString[j].lower() :
16             return False
17         i += 1
18         j -= 1
19         
20     return True
21     
22 print complexPalindrome("Aha")
23 print complexPalindrome("AHA")
24 print complexPalindrome("Race car")
25 print complexPalindrome("a")
26 

5。playGame()
Repeatedly issues intelligent guesses to the guessing game you built in tutorial. See below for
more detailed information.
In tutorial, you saw a game that two players play together - one player chooses the number and
the other player guesses it, and the computer tells the 2nd player if the guess was too high or too
low. Now, you will write a computer program that actually plays the game – it will make smart
guesses until it finds the right answer.
The Rules
1. The user will pick a number between 1 & 100 (but not tell the computer what it is)
2. The computer will make a guess
3. The user will tell the computer whether its guess was too high, too low, or right on
4. Steps 2 & 3 repeat until the computer guesses right, when it will output “I got it!”
要求是在0-100之间让电脑猜数字, 电脑猜了之后问你他猜的是大了还是小了, 你要输入大了小了还是对了, 一直到猜对为止。
列子:
playGame()
>>> game()
I guess 50
Am I too high (1), too low(2), or right on? (3)
1
I guess 25
Am I too high (1), too low(2), or right on? (3)
1
I guess 12
Am I too high (1), too low(2), or right on? (3)
2
I guess 18
Am I too high (1), too low(2), or right on? (3)
1
I guess 15
Am I too high (1), too low(2), or right on? (3)
2
I guess 16
Am I too high (1), too low(2), or right on? (3)
2
I guess 17
Am I too high (1), too low(2), or right on? (3)
3
I got it!

 1 #!/usr/bin/python
 2 # Filename: 5.py
 3 
 4 
 5 def playGame() :
 6     _min = 0
 7     _max = 100    
 8     while True :
 9         num = (_min + _max) // 2
10         print "I guess " + str(num)
11         print "Am I too high(1), too low(2), or right on? (3)"
12         act = int(input())
13         if act == 1 :
14             _max = num
15         elif act == 2 :
16             _min = num
17         else :
18             print "I got it!"
19             break    
20 
21     
22     
23 playGame()
24