2020-04
15

反正这是我的答案

By xrspook @ 19:44:55 归类于: 扮IT

题目摆在这里,没有确切的答案,下面是我的解答,对不对不知道。words.txt资源在这里。

There are solutions to these exercises in the next section. You should at least attempt each one before you read the solutions.

Exercise 1: Write a program that reads words.txt and prints only the words with more than 20 characters (not counting whitespace).

Exercise 2: In 1939 Ernest Vincent Wright published a 50,000 word novel called Gadsby that does not contain the letter “e”. Since “e” is the most common letter in English, that’s not easy to do. In fact, it is difficult to construct a solitary thought without using that most common symbol. It is slow going at first, but with caution and hours of training you can gradually gain facility. All right, I’ll stop now. Write a function called has_no_e that returns True if the given word doesn’t have the letter “e” in it. Write a program that reads words.txt and prints only the words that have no “e”. Compute the percentage of words in the list that have no “e”.

Exercise 3: Write a function named avoids that takes a word and a string of forbidden letters, and that returns True if the word doesn’t use any of the forbidden letters. Write a program that prompts the user to enter a string of forbidden letters and then prints the number of words that don’t contain any of them. Can you find a combination of 5 forbidden letters that excludes the smallest number of words?

Exercise 4: Write a function named uses_only that takes a word and a string of letters, and that returns True if the word contains only letters in the list. Can you make a sentence using only the letters acefhlo? Other than “Hoe alfalfa”?

Exercise 5: Write a function named uses_all that takes a word and a string of required letters, and that returns True if the word uses all the required letters at least once. How many words are there that use all the vowels aeiou? How about aeiouy?

Exercise 6: Write a function called is_abecedarian that returns True if the letters in a word appear in alphabetical order (double letters are ok). How many abecedarian words are there?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
fin = open('words.txt') # 第1小问
for line in fin:
    if len(line) >= (20+2):
        word = line.strip()
        print(word)
# counterdemonstrations
# hyperaggressivenesses
# microminiaturizations
 
def has_no_e(word): # 第2小问
    for letter in word:
        if letter == 'e':
            return False
    return True
fin = open('words.txt')
all = 0
count = 0
for line in fin:
    word = line.strip()
    all = all + 1
    if has_no_e(word):
        print(word)
        count = count + 1
print(count, 'words without e')
print('{:.0%}'.format(count/all), 'words without e')
# ...
# zymosis
# zymotic
# zymurgy
# 37641 words without e
# 33% words without e
 
def avoids(word, x): # 第3小问,最后一个问题举手投降
    for letterw in word:
        for letterx in x:
            if letterw == letterx:
                return False
    return True
fin = open('words.txt')
x = input('withtout: ')
num = 0
# word = 'jwrojgre' # input('word is ')
# print(avoids(word, x))
for line in fin:
    word = line.strip()
    if avoids(word, x):
        num = num + 1
print(num, 'words without', x)
# withtout: aeiou
# 107 words without aeiou
# count = 0
# import itertools
# for i in itertools.combinations('abcdefghijklmnopqrstuvwxyz', 5):
#     print(''.join(i))
#     count = count + 1
# print(count) # 65780个排列组合的可能性啊啊啊啊啊啊
 
 
def uses_only(word, x): # 第4小问
    for letter in word:
        if letter not in x:
            return False
    return True
word = input('word is ')
x = input('uses is ')
print(uses_only(word, x))
# word is abc
# uses is efg
# False
 
def uses_all(word, x): # 第5小问
    for letter in x:
        if letter not in word:
            return False
    return True
fin = open('words.txt')
x = input('must use: ' )
num = 0
for line in fin:
    word = line.strip()
    if uses_all(word, x):
        num = num + 1
print(num, 'words with', x)
# must use: aeiou
# 598 words with aeiou
# must use: aeiouy
# 42 words with aeiouy
 
def is_abecedarian(word): # 第6小问
    index = 1
    while index < len(word) - 1:
        if ord(word[index-1]) > ord(word[index]):
            return False
        index = index + 1
    return True
fin = open('words.txt')
num = 0
for line in fin:
    word = line.strip()
    if is_abecedarian(word):
        num = num + 1
print(num, 'words is abecedarian')
# 1573 words is abecedarian
2020-04
15

字符偏移加密

By xrspook @ 13:28:09 归类于: 扮IT

本来我根本没考虑字母以外的那些怎么办,测试过参考答案以后,发现原来字母以外的东西原始输出,于是我也这般弄了,等于再加一个是否字母的判断,折腾。不告诉人家怎么把字符合并成字符串,我就只好准备两个对象二人转连接。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def rotate_word(something, n): # a-z: 97-122, A-Z: 65-90
    newletter1 = ''
    for letter in something:
        if ord(letter) < ord('A') or ord('Z') < ord(letter) < ord('a') or ord('z') < ord(letter):
            newletter2 = newletter1 + letter
        else:
            if ord(letter) + n > ord('z'):
                newletter2 = newletter1 + chr(ord(letter) + n - 26)
            elif ord('a') > ord(letter) + n > ord('Z'):
                newletter2 = newletter1 + chr(ord(letter) + n - 26)
            else:
                newletter2 = newletter1 + chr(ord(letter) + n)
        newletter1 = newletter2
    return newletter2
something = input('please write something: ')
n = int(input('how many shifts do you want: '))
print('before:', something)
print('after :', rotate_word(something, n))
# please write something: IBM
# how many shifts do you want: -1
# before: IBM
# after : HAL
# please write something: g858^h{O
# how many shifts do you want: 6
# before: g858^h{O
# after : m858^n{U
2020-04
15

我要早睡

By xrspook @ 8:54:49 归类于: 烂日记

昨天晚上我的确提早回宿舍了,9点多一点我就回宿舍。之前我的打算是7点半就开始运动,那么9点之前我就可以回宿舍,但是,我还是拖延症到了8点才开始。运动很愉快,电影也很愉快。感觉我已经好久都没看过这么愉快的电影。过去好些时间,我都在看国产片,之所以这样,因为我对欧美电影已经失去了兴趣。大多数情况下,我在看国产片,也会看一下印度电影或者韩国电影,日本电影过于文艺,我有点难以接受。难以接受归难以接受,也总比根本不看好。

现在我已经不敢看我自己的记录了,感觉我已经接近了两个月大姨妈没来。到底什么时候要来?我完全说不准,因为貌似一点征兆都没有。唯一能拯救我的就只有早睡。肥胖跟大姨妈两个的关系很暧昧。对我来说,肥胖就意味着大姨妈一定不靠谱,而大姨妈不靠谱就意味着肥胖是条不归路。所以他俩到底是谁先挑起这个死循环,我至今没摸透,但可以确定的是,晚睡直接会导致我的大姨妈不来。要我做到10点半就睡觉几乎是不可能的事。如果我要做到10点半就睡觉,意味着9点半之前我必须回到宿舍,开始洗澡洗衣服,然后做一下其它。从前这对我来说太简单,但现在,这对我来说,不是一般的难。昨晚我的确做到了早回宿舍,我10点之前就已经洗完澡。但问题是,因为今天审计要过来,所以我又加班了一个小时。日常的工作15分钟以内我就搞定了,但余下的事情,不断地核对数据,不断地这个表那个表耗费了我不少时间,虽然我觉得自己的核对思路还是挺清晰的,因为我就只是重复那几件事而已,但是还是要时间。因为是在自己的笔记本上操作。屏幕太小,数字键不是我习惯的小键盘。虽然过去好些时间我已经在努力在练习用字母上面的一行数字,而不只靠小键盘过日子。有些时候,操控那一行数字,我可以做到条件反射,比如在输入日期的时候,2020这个数字我已经很熟练了,但是叫我输入一段数字的时候,我总是要想一想那个数字在哪个位置,应该用哪个手指去点击。大概在这种情况下,你或许会觉得我直接看着那个数字用一根手指按会更快,但是我还是纠结地把10根手指都放在上面,想一想我应该用哪个,眼睛盯着显示器,保证自己没有按错。

已经在这个单位干了12年,这是我第一次遇到审计的人过来查我们的东西。其实准确来说不是我们的东西,那是总公司的东西。审计本来是去查总公司的,但是总公司是一个汇总,所以他们又下到了基层单位去查。过去这些年,我遇到过不少的检查组。因为我们是省直单位,所以相对来说东莞市来查的几率会低一点,虽然我们单位的粮食存量不少,但相对来说,其实跨省和国家来检查的也不是很多。大型的清仓查库都被我碰上了,完全没出现什么状况,因为实际上也没有状况。小型的事务所之类,每年都要来一次。每年上面的监管单位派过来的事务所都不一样,大概是免得我们去搞关系。即便这样的随机抓取,也不曾发现过我们有什么大问题。可能会有一些细节上的差错,比如说手误写错日期之类的。但是根本性的问题一定不会存在。

今天过来查,昨天中午才告诉我有这么件事,才开始叫我们准备。我也说不上这是好还是不好,根本没时间给你准备,那平时是怎样,就怎么去面对。我不知道要紧张些什么,我只是陪同大家一同紧张而已。

2020-04
14

一句秒杀一段话

By xrspook @ 19:52:09 归类于: 扮IT

还记得初中的时候数学老师跟我说初等数学比高等数学难多了,幸好,我这辈子暂时只学过高等数学,而且几乎都还给大学老师了……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# def first(word):
#     return word[0]
# def last(word):
#     return word[-1]
# def middle(word):
#     return word[1:-1]
# def is_palindrome(word):
#     if len(word) <= 1:
#         return True
#     elif first(word) != last(word):
#         return False
#     else:
#         return is_palindrome(middle(word))
def is_palindrome(word):
    return word[::-1] == word
word = input('word is ')
print(is_palindrome(word))
# word is qwerreq
# False
# word is poiuuiop
# True
2020-04
14

By xrspook @ 9:19:49 归类于: 烂日记

当外人觉得我们国家是一党专政就嗤之以鼻的时候,有些国家还不是一人专政,那跟封建时代皇帝说了算有什么区别?他要解雇谁就是一句话的事,无论那个人是真的没用,还是因为那个人很有用,但却跟那个王有矛盾,所以他被干掉了。有时我觉得那些被解雇的人挺神奇的,在这样一个“封建”统治之下,他们怎么还能忍着继续在那里干呢?不过,如果他们放弃在那里干,他们就根本无法改变那个“封建专制”瞎白胡来的局面。一方面我觉得,他们真的很有勇气,但另一方面,我感觉到他们极端的无奈,我甚至会同情他们。或许在我的国家,也有这种事,也有被打压,但是我看不到。无论在哪个体制里,肯定会存在这样的事情,但是,国家的领导人每天像在开脱口秀一样口无遮拦,这实在让人觉得非常的无语,甚至连吐槽也觉得毫无意义了。幸好,我不生在那个国家,我也不是那个国家的公民,所以我无需烦恼。顶多不去理会他就行了。

我妈说,别的国家里也有很多英雄,但是他们不会像我们这样,天天在歌颂、赞扬,他们在默默的做事。我不知道我妈是怎么想的,大概她微信群里的东西看多了。到底是哪个社会更喜欢造英雄,这是显而易见的。中国有非常悠久的历史。在过去的历史中,随手一抓,到处都是英雄。但是有些国家根本谈不上有多少历史,所以他们就只有脑洞大开,创造他们的英雄。他们的英雄难道还少吗?我妈之所以没感觉,大概是因为她根本没怎么接触过那些东西。你问问现在的年轻人。问问他们的英雄是谁?那都太显而易见了。在新冠疫情这个特殊时刻,我们为什么要树立自己的英雄?一定程度上,我觉得这是一个策略,要让年轻人把关注重点转回到国内,转回到我们自己身边,必须有民族自豪感,然后你才会热爱工作、热爱生活、珍惜身边的美好,而不是做那些科幻的梦。我妈说,她亲眼见识过那些过做采访的人写出来的东西完全偏离事实。那些记者媒体人之类的,想怎么吹就怎么吹,简直可以称得上是胡编乱造。我心目中的文艺界,东西从来不完全是真的,即便那是一个纪录片。只有身边的人做的确切的事才是真的。如果你看到的那些东西都平淡如水,你还有兴趣看下去吗?有些人对一些真人真事改编的影视作品嗤之以鼻,觉得那是丑化、觉得那是挖苦的时候,他们怎么就不能理解那是艺术的夸张?我们没有乱吹,我们身边没有三头六臂的神,没有超人能拯救我们世界。我们可能只是把不是一个人的优点都叠加到了一个人身上而已。他们跟我们一样,都是血肉之躯。我不知道我妈一定程度上为什么不能被这些感动。

不知道是什么样的教育让我成为一个感性的人。我很容易生气,经常吐槽,但是我也很容易被一些小事情所感动。当我妈对某些事情激动不已的时候,我会选择选择性忽略。如果她也可以像我这样的话,估计她的人生会过得轻松很多,但就因为她在某些事情上非常动真格、非常斤斤计较,所以她做事才会那么的仔细。

爱国是因为这个国家成就了我,所以我也必须为这个国家做点什么。星星点点的大家做好自己,就是爱国。

© 2004 - 2026 我的天 | Theme by xrspook | Power by WordPress