Skip to content

添加了中文和python3代码 #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions 1-50/1-10/1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
编写一个程序,找出所有能被7整除但不是5的倍数的数字,

between 2000 and 3200 (both included).
2000至3200(均包括在内)。

The numbers obtained should be printed in a comma-separated sequence on a single line.
获得的数字应以逗号分隔的顺序打印在一行上。

"""

for i in range(2000, 3201):
if i % 7 == 0 and i % 5 != 0:
print(i, end=',')

43 changes: 43 additions & 0 deletions 1-50/1-10/10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
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
再次,hello创造了完美的实践世界

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.
我们使用set容器自动删除重复的数据,然后使用sorted()对数据进行排序。
"""

a=list(set(input().split(" ")))
a.sort()
print(' '.join(a))

"""
sorted会创造一个新的列表,并返回一个新的列表,而不是在原地排序
sort在原来的列表进行排序,并返回None

Sorted will create a new list and return a new list instead of sorting in place
Sort sorts the original list and returns None

sorted可对任何可以排序的数据结构进行排序,包括列表、元组、字符串等
sort只能对列表进行排序

Sorted can sort any data structure that can be sorted, including lists, tuples, strings, etc
Sort can only sort a list
"""
24 changes: 24 additions & 0 deletions 1-50/1-10/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Write a program which can compute the factorial of a given numbers.
编写一个程序,可以计算给定数字的阶乘。

The results should be printed in a comma-separated sequence on a single line.
结果应以逗号分隔的顺序打印在一行上。

Suppose the following input is supplied to the program:
假设向程序提供了以下输入:

8

Then, the output should be:
那么,输出应该是:

40320

"""

num=1
n=int(input("请输入一个数字:"))
for i in range(1,n+1):
num=num*i
print(num)
21 changes: 21 additions & 0 deletions 1-50/1-10/3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
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.
对于给定的整数n,编写一个程序来生成一个包含(i,i*i)的字典。该字典是1和n之间的整数(两者都包括在内)然后程序应该打印字典。

Suppose the following input is supplied to the program:
假设向程序提供了以下输入:

8

Then, the output should be:
那么,输出应该是:

{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}

"""

n=int(input("请输入一个数字:"))
a={}
for i in range(1,n+1):
a[i]=i*i
print(a)
21 changes: 21 additions & 0 deletions 1-50/1-10/4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.
编写一个程序,从控制台接受逗号分隔的数字序列,并生成一个包含每个数字的列表和元组。

Suppose the following input is supplied to the program:
假设向程序提供了以下输入:

34,67,55,33,12,98

Then, the output should be:
那么,输出应该是:

['34', '67', '55', '33', '12', '98']
('34', '67', '55', '33', '12', '98')

"""

a=input()
b=tuple(a.split (','))
c=a.split(',')
print(b,c)
34 changes: 34 additions & 0 deletions 1-50/1-10/5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Define a class which has at least two methods:
定义一个至少有两个方法的类:

getString: to get a string from console input
getString:从控制台输入中获取字符串

printString: to print the string in upper case.
printString:打印大写字符串。

Also please include simple test function to test the class methods.
另外,请包含简单的测试函数来测试类方法。

Hints:
提示:

Use __init__ method to construct some parameters
使用__init__方法构造一些参数

"""

class stringa:
def __init__(self):
self.str1= ""

def getstring(self):
self.str1=input("请输入字符串:")

def printstring(self):
print(self.str1.upper())

s=stringa()
s.getstring()
s.printstring()
47 changes: 47 additions & 0 deletions 1-50/1-10/6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Write a program that calculates and prints the value according to the given formula:
编写一个程序,根据给定的公式计算并打印值:

Q = Square root of [(2 * C * D)/H]
Q=[(2*C*D)/H]**0.5

Following are the fixed values of C and H:
以下是C和H的固定值,

C is 50. H is 30.
C是50。H是30。

D is the variable whose values should be input to your program in a comma-separated sequence.
D是变量,其值应以逗号分隔的顺序输入到程序中。

Example
例子

Let us assume the following comma separated input sequence is given to the program:
让我们假设程序有以下逗号分隔的输入序列:

100,150,180

The output of the program should be:
程序的输出应该是:

18,22,24

Hints:
提示:
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)
如果接收到的输出是十进制形式的,则应四舍五入到最接近的值(例如,如果收到的输出是26.0,则应打印为26)

In case of input data being supplied to the question, it should be assumed to be a console input.
如果输入数据被提供给问题,则应假设它是控制台输入。
"""

def task(d):
c=50
h=30
q=int(((2*c*d)/h)**0.5)
return q

a=list((input("输入数字").split(",")))
for i in a:
print(task(int(i)),end=",")
27 changes: 27 additions & 0 deletions 1-50/1-10/7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
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.
编写一个程序,以2位数字X、Y为输入,生成一个二维数组。数组第i行和第j列中的元素值应为i*j。

Example
例子

Suppose the following inputs are given to the program:
假设程序有以下输入:

3,5

Then, the output of the program should be:
那么,程序的输出应该是:

[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

"""

a,b=map(int,input("a,b=").split(','))
c=[]
for i in range(a):
d=[]
for j in range(b):
d.append(i*j)
c.append(d)
print(c)
20 changes: 20 additions & 0 deletions 1-50/1-10/8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
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.
编写一个程序,接受逗号分隔的单词序列作为输入,并在按字母顺序排序后以逗号分隔的顺序打印单词。

Suppose the following input is supplied to the program:
假设向程序提供了以下输入:

without,hello,bag,world


Then, the output should be:
那么,输出应该是:

bag,hello,without,world

"""

str_list=input("输入单词序列(Input word sequence):").split(',')
str_list.sort()
print(','.join(str_list))
27 changes: 27 additions & 0 deletions 1-50/1-10/9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
编写一个程序,接受行序列作为输入,并在将句子中的所有字符大写后打印行。

Suppose the following input is supplied to the program:
假设向程序提供了以下输入:

Hello world
Practice makes perfect

Then, the output should be:
那么,输出应该是:

HELLO WORLD
PRACTICE MAKES PERFECT

"""

a=[]
while 1==1:
s=input()
if s:
a.append(s.upper())
else:
break
for k in a:
print(k)
26 changes: 26 additions & 0 deletions 1-50/11-20/11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
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.
编写一个程序,接受逗号分隔的4位二进制数序列作为输入,然后检查它们是否能被5整除。可被5整除的数字将以逗号分隔的顺序打印。

Example:
例子:

0100,0011,1010,1001

Then the output should be:
那么输出应该是:

1010

Notes: Assume the data is input by console.
注:假设数据是通过控制台输入的。

"""

a=input().split(",")
c=[]
for i in a:
b=int(i,2)
if b%5==0:
c.append(i)
print(','.join(c))
26 changes: 26 additions & 0 deletions 1-50/11-20/12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
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.
编写一个程序,它将找到1000到3000之间的所有的每一位都是偶数的数字(包括1000和3000)。

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.
如果输入数据被提供给问题,则应假设它是控制台输入。

"""

num=[]
for i in range(1000,3001):
a=i
while a>0:
b=a%10
a//=10
if b%2!=0:
break
else:
num.append(str(i))
print(','.join(num))
25 changes: 25 additions & 0 deletions 1-50/11-20/13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
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
"""

str1=input()
a={'LETTERS':0 ,'DIGITS':0}
for i in str1:
if i.isalpha():
a['LETTERS']+=1
elif i.isdigit():
a['DIGITS']+=1
print('LETTERS',a['LETTERS'])
print('DIGITS',a['DIGITS'])
Loading