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')

python小练手题1的更多相关文章

  1. python 小练手

    监控 主动监控 - 服务器端轮询客户端 被动监控-客户端agent上报到服务器端 混合模式---两种都支持 需求 1个性化的监控需求 2每个服务的监控间隔不同 3混合模式的监控

  2. Python—经典练手题目汇总

    Python-经典练手题目汇总 # 1.有1020个西瓜,第一天卖掉总数的一半后又多卖出两个,以后每天卖剩下的一半多两# 个,问几天以后能卖完? day=0 xg=1020 for i in rang ...

  3. Python新手练手项目

    1.新手练手项目集中推荐 https://zhuanlan.zhihu.com/p/22164270 2.Python学习网站 https://www.shiyanlou.com 3.数据结构可视化学 ...

  4. Python适合练手的项目

    原文地址:https://www.jianshu.com/p/039156321e30 项目地址:https://github.com/DeqianBai/Python-Project/tree/ma ...

  5. python爬虫练手项目快递单号查询

    import requests def main(): try: num = input('请输入快递单号:') url = 'http://www.kuaidi100.com/autonumber/ ...

  6. 【python小练】0014题 和 0015 题

    第 0014 题: 纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示: { ":["张三",150,120,100], ":[& ...

  7. 【python小练】0012题

    第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好 ...

  8. 【python小练】0011题

    第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights. #word.tx ...

  9. 【python小练】0013

    第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-) 科科...妹子就算了,大晚上的爬点吃的吧.食物图集:抿一口,舔一舔,扭一扭~·SCD 写个简单的爬图爬虫 ...

随机推荐

  1. 创建vue 项目

    sudo npm install -g @vue/cli-init vue init webpack my-project cd my-project/ npm install npm run dev

  2. 华为HCNA乱学Round 1:登录权限

    由于公司要用到华为设备,以前也学得比较基础就顺便补充一下.

  3. 实习第一个月总结(const关键字、条件编译、volatile关键字、#和##的作用、函数指针)

    C语言中const关键字的作用: 修饰局部变量或者全局变量,表示变量n的值不能被改变了 修饰指针,分为常量指针与指针常量,也可以两者结合 常量指针指向的值不能改变,但是这并不是意味着指针本身不能改变, ...

  4. Linux第三阶段题型测试

    1.如何取得/etiantian文件的权限对应的数字内容,如-rw-r--r--为644,要求使用命令取得644或0644这样的数字. 解答: 1)最土的方法:ls -l /etiantian |cu ...

  5. cmake升级到3.10以上

    使用yun install cmake3 安装 ,不会覆盖centos7 cmake 1 添加cmake3 源 echo '[group_kdesig-cmake3_EPEL]name=Copr re ...

  6. oracle——学习之路(oracle内置函数)

    oracle与很多内置函数,主要分为单行函数与集合函数. 首先要提一下dual表,它oracle的一个表,没有什么实质的东西,不能删除它,否则会造成Oracle无法启动等问题,他有很大用处,可以利用它 ...

  7. Java更新Oracle的clob类型字段

    Java更新Oracle的clob类型字段 1.查询该clob字段 2.处理该clob字段查询结果 3.更新该clob字段查询结果 1.查询该clob字段 <select id="se ...

  8. sqlyog注释的快捷键-先收藏

    在学习使用sqlyog的时候,想要多行注释SQL语句,就去网上找了相关的快捷键,与大家分享,网上有很多! Ctrl+M 创建一个新的连接Ctrl+N 使用当前设置新建连接Ctrl+F4 断开当前连接 ...

  9. docker学习笔记之把容器commit成镜像

    docker提供了两种镜像制作的方式,提高了使用的灵活性: 1.可以将更改后的容器提交,制作成镜像(这是接下来要说明的) 2.通过Dockerfile来制作镜像 下面通过一个例子来展示方法1. 本地有 ...

  10. Codeforces 1244G. Running in Pairs

    传送门 首先对于两个排列 $A,B$ 我们可以把 $A$ 从小到大排序并把 $B$ 重新和 $A$ 一一对应 显然这样不会影响 $\sum_{i=1}^{n}max(A_i,B_i)$ 的值 所以直接 ...