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

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

博客园 - 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