
1.
"""
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 = int(input('请输入需要计算的数:'))
def fact(num):
if num == 0:
return 1
return num * fact(num-1)
print(fact(num))
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.
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}
"""
num = int(input('请输入'))
d = {}
for i in range(1,num+1):
d.update({i:i*i})
print(d)
3.
"""
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')
"""def spl(word):
li = []
for i in word.split(','):
li.append(i)
print()
tup = '('+str(li)[1:-1]+')'
return print(li,'\n',tup)
word = input("")
spl(word)
4.
"""
Write a program that calculates and prints the value according to the given formula:
Q = Square root of [(2 * C * D)/H]
Following are the fixed values of C and H:
C is 50. H is 30.
D is the variable whose values should be input to your program in a comma-separated sequence.
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
"""
import math
def fun(D):
C = 50
H = 30
li = []
for d in D.split(','):
Q = int(math.sqrt((2 * C * int(d)) / H))
li.append(Q)
return print(str(li)[1:-1])
D = input()
fun(D)
5.
"""
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.
Note: i=0,1.., X-1; j=0,1,¡Y-1.
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]]
"""
def array(x,y):
li = []
for i in range(x):
li.append([])
for j in range(y):
li[i].append(0)
li[i][j] = i*j
return print(li)
array(3,5)
6.
"""
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
"""
def fun(word):
li = [w for w in (word.split(','))]
li.sort()
# new = sorted(li,key=lambda i:i[0])
return print(','.join(li))
fun('without,hello,bag,world')
7.
"""
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
"""
def fun():
li = []
while True:
s = input()
if s:
li.append(s.upper())
continue
else:
for i in li:
print(i)
break
fun()
8.
"""
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.
"""
def fun(word):
li = []
for i in word.split(','):
if int(i,base=2)%5==0:
li.append(i)
return print(','.join(li))
fun('0100,0011,1010,1001')
9.
"""
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.
"""
def fun():
li = []
flag = 0
for i in range(1000,3000):
for j in list(str(i)):
if int(j)%2 == 0:
flag += 1
if flag == 4:
li.append(i)
flag = 0
else:
flag = 0
return print(li)
fun()
10.
"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""
"""
import re
def fun(word):
alp = re.findall('[a-z,A-Z]',word)
num = re.findall('[0-9]',word)
return print('字母{}\n数字{}'.format(len(alp),len(num)))
fun('hello world! 123')

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人