Skip to content

Commit 5266365

Browse files
committed
1
1
1 parent 9252020 commit 5266365

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+5813
-2365
lines changed

1-50/1-10/1.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
3+
编写一个程序,找出所有能被7整除但不是5的倍数的数字,
4+
5+
between 2000 and 3200 (both included).
6+
2000至3200(均包括在内)。
7+
8+
The numbers obtained should be printed in a comma-separated sequence on a single line.
9+
获得的数字应以逗号分隔的顺序打印在一行上。
10+
11+
"""
12+
13+
for i in range(2000, 3201):
14+
if i % 7 == 0 and i % 5 != 0:
15+
print(i, end=',')
16+

1-50/1-10/10.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
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.
3+
编写一个程序,接受一系列空格分隔的单词作为输入,并在删除所有重复单词并按字典序排序后打印单词。
4+
5+
Suppose the following input is supplied to the program:
6+
假设向程序提供了以下输入:
7+
8+
hello world and practice makes perfect and hello world again
9+
你好世界,熟能生巧,再次你好世界
10+
11+
Then, the output should be:
12+
那么,输出应该是:
13+
14+
again and hello makes perfect practice world
15+
再次,hello创造了完美的实践世界
16+
17+
Hints:
18+
提示:
19+
20+
In case of input data being supplied to the question, it should be assumed to be a console input.
21+
如果输入数据被提供给问题,则应假设它是控制台输入。
22+
23+
We use set container to remove duplicated data automatically and then use sorted() to sort the data.
24+
我们使用set容器自动删除重复的数据,然后使用sorted()对数据进行排序。
25+
"""
26+
27+
a=list(set(input().split(" ")))
28+
a.sort()
29+
print(' '.join(a))
30+
31+
"""
32+
sorted会创造一个新的列表,并返回一个新的列表,而不是在原地排序
33+
sort在原来的列表进行排序,并返回None
34+
35+
Sorted will create a new list and return a new list instead of sorting in place
36+
Sort sorts the original list and returns None
37+
38+
sorted可对任何可以排序的数据结构进行排序,包括列表、元组、字符串等
39+
sort只能对列表进行排序
40+
41+
Sorted can sort any data structure that can be sorted, including lists, tuples, strings, etc
42+
Sort can only sort a list
43+
"""

1-50/1-10/2.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Write a program which can compute the factorial of a given numbers.
3+
编写一个程序,可以计算给定数字的阶乘。
4+
5+
The results should be printed in a comma-separated sequence on a single line.
6+
结果应以逗号分隔的顺序打印在一行上。
7+
8+
Suppose the following input is supplied to the program:
9+
假设向程序提供了以下输入:
10+
11+
8
12+
13+
Then, the output should be:
14+
那么,输出应该是:
15+
16+
40320
17+
18+
"""
19+
20+
num=1
21+
n=int(input("请输入一个数字:"))
22+
for i in range(1,n+1):
23+
num=num*i
24+
print(num)

1-50/1-10/3.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.
3+
对于给定的整数n,编写一个程序来生成一个包含(i,i*i)的字典。该字典是1和n之间的整数(两者都包括在内)然后程序应该打印字典。
4+
5+
Suppose the following input is supplied to the program:
6+
假设向程序提供了以下输入:
7+
8+
8
9+
10+
Then, the output should be:
11+
那么,输出应该是:
12+
13+
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
14+
15+
"""
16+
17+
n=int(input("请输入一个数字:"))
18+
a={}
19+
for i in range(1,n+1):
20+
a[i]=i*i
21+
print(a)

1-50/1-10/4.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.
3+
编写一个程序,从控制台接受逗号分隔的数字序列,并生成一个包含每个数字的列表和元组。
4+
5+
Suppose the following input is supplied to the program:
6+
假设向程序提供了以下输入:
7+
8+
34,67,55,33,12,98
9+
10+
Then, the output should be:
11+
那么,输出应该是:
12+
13+
['34', '67', '55', '33', '12', '98']
14+
('34', '67', '55', '33', '12', '98')
15+
16+
"""
17+
18+
a=input()
19+
b=tuple(a.split (','))
20+
c=a.split(',')
21+
print(b,c)

1-50/1-10/5.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Define a class which has at least two methods:
3+
定义一个至少有两个方法的类:
4+
5+
getString: to get a string from console input
6+
getString:从控制台输入中获取字符串
7+
8+
printString: to print the string in upper case.
9+
printString:打印大写字符串。
10+
11+
Also please include simple test function to test the class methods.
12+
另外,请包含简单的测试函数来测试类方法。
13+
14+
Hints:
15+
提示:
16+
17+
Use __init__ method to construct some parameters
18+
使用__init__方法构造一些参数
19+
20+
"""
21+
22+
class stringa:
23+
def __init__(self):
24+
self.str1= ""
25+
26+
def getstring(self):
27+
self.str1=input("请输入字符串:")
28+
29+
def printstring(self):
30+
print(self.str1.upper())
31+
32+
s=stringa()
33+
s.getstring()
34+
s.printstring()

1-50/1-10/6.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Write a program that calculates and prints the value according to the given formula:
3+
编写一个程序,根据给定的公式计算并打印值:
4+
5+
Q = Square root of [(2 * C * D)/H]
6+
Q=[(2*C*D)/H]**0.5
7+
8+
Following are the fixed values of C and H:
9+
以下是C和H的固定值,
10+
11+
C is 50. H is 30.
12+
C是50。H是30。
13+
14+
D is the variable whose values should be input to your program in a comma-separated sequence.
15+
D是变量,其值应以逗号分隔的顺序输入到程序中。
16+
17+
Example
18+
例子
19+
20+
Let us assume the following comma separated input sequence is given to the program:
21+
让我们假设程序有以下逗号分隔的输入序列:
22+
23+
100,150,180
24+
25+
The output of the program should be:
26+
程序的输出应该是:
27+
28+
18,22,24
29+
30+
Hints:
31+
提示:
32+
If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26)
33+
如果接收到的输出是十进制形式的,则应四舍五入到最接近的值(例如,如果收到的输出是26.0,则应打印为26)
34+
35+
In case of input data being supplied to the question, it should be assumed to be a console input.
36+
如果输入数据被提供给问题,则应假设它是控制台输入。
37+
"""
38+
39+
def task(d):
40+
c=50
41+
h=30
42+
q=int(((2*c*d)/h)**0.5)
43+
return q
44+
45+
a=list((input("输入数字").split(",")))
46+
for i in a:
47+
print(task(int(i)),end=",")

1-50/1-10/7.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.
3+
编写一个程序,以2位数字X、Y为输入,生成一个二维数组。数组第i行和第j列中的元素值应为i*j。
4+
5+
Example
6+
例子
7+
8+
Suppose the following inputs are given to the program:
9+
假设程序有以下输入:
10+
11+
3,5
12+
13+
Then, the output of the program should be:
14+
那么,程序的输出应该是:
15+
16+
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
17+
18+
"""
19+
20+
a,b=map(int,input("a,b=").split(','))
21+
c=[]
22+
for i in range(a):
23+
d=[]
24+
for j in range(b):
25+
d.append(i*j)
26+
c.append(d)
27+
print(c)

1-50/1-10/8.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.
3+
编写一个程序,接受逗号分隔的单词序列作为输入,并在按字母顺序排序后以逗号分隔的顺序打印单词。
4+
5+
Suppose the following input is supplied to the program:
6+
假设向程序提供了以下输入:
7+
8+
without,hello,bag,world
9+
10+
11+
Then, the output should be:
12+
那么,输出应该是:
13+
14+
bag,hello,without,world
15+
16+
"""
17+
18+
str_list=input("输入单词序列(Input word sequence):").split(',')
19+
str_list.sort()
20+
print(','.join(str_list))

1-50/1-10/9.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
3+
编写一个程序,接受行序列作为输入,并在将句子中的所有字符大写后打印行。
4+
5+
Suppose the following input is supplied to the program:
6+
假设向程序提供了以下输入:
7+
8+
Hello world
9+
Practice makes perfect
10+
11+
Then, the output should be:
12+
那么,输出应该是:
13+
14+
HELLO WORLD
15+
PRACTICE MAKES PERFECT
16+
17+
"""
18+
19+
a=[]
20+
while 1==1:
21+
s=input()
22+
if s:
23+
a.append(s.upper())
24+
else:
25+
break
26+
for k in a:
27+
print(k)

0 commit comments

Comments
 (0)