Question 10
Question
Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.
Suppose the following input is supplied to the program:
hello world and practice makes perfect and hello world again
Then, the output should be:
again and hello makes perfect practice world
Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.We use set container to remove duplicated data automatically and then use sorted() to sort the data.


summary:
1.其實(shí)參考答案中提供的利用count函數(shù)的方法更加的實(shí)用,也更加的簡(jiǎn)單
Python count() 方法用于統(tǒng)計(jì)字符串里某個(gè)字符出現(xiàn)的次數(shù)??蛇x參數(shù)為在字符串搜索的開(kāi)始與結(jié)束位置。
count()方法語(yǔ)法:
"""
str.count(sub, start= 0,end=len(string))
"""
參數(shù)
sub -- 搜索的子字符串
start -- 字符串開(kāi)始搜索的位置。默認(rèn)為第一個(gè)字符,第一個(gè)字符索引值為0。
end -- 字符串中結(jié)束搜索的位置。字符中第一個(gè)字符的索引為 0。默認(rèn)為字符串的最后一個(gè)位置。
2.Python中sort ()與 sorted() 區(qū)別
sort 與 sorted 區(qū)別:
sort 是應(yīng)用在 list 上的方法,屬于列表的成員方法,sorted 可以對(duì)所有可迭代的對(duì)象進(jìn)行排序操作。
list 的 sort 方法返回的是對(duì)已經(jīng)存在的列表進(jìn)行操作,而內(nèi)建函數(shù) sorted 方法返回的是一個(gè)新的 list,而不是在原來(lái)的基礎(chǔ)上進(jìn)行的操作。
sort使用方法為ls.sort(),而sorted使用方法為sorted(ls)。
Question 11
Question
Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.
Example:
0100,0011,1010,1001
Then the output should be:
1010
Notes: Assume the data is input by console.
Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.

summary:
這部分的題目主要設(shè)計(jì)的問(wèn)題難點(diǎn)我認(rèn)為在于進(jìn)制的轉(zhuǎn)換

上圖很好的說(shuō)明了進(jìn)制之間轉(zhuǎn)換的函數(shù),感覺(jué)并不是很常用,返回的值是字符串,會(huì)帶有前綴,其實(shí)在題目的最后應(yīng)該再用下字符串分割把前綴刪除
Question 12
Question: Write a program, which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.The numbers obtained should be printed in a comma-separated sequence on a single line.
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.

Question 13
Question: Write a program that accepts a sentence and calculate the number of letters and digits.
Suppose the following input is supplied to the program:
hello world! 123 Then, the output should be:
LETTERS 10 DIGITS 3 Hints: In case of input data being supplied to the question, it should be assumed to be a console input.

summary:主要是isalpha()和isnumeric()的使用判斷。