有以下几个数字:1、2、3、4、5,能组成多少个互不相同且无重复数字的三位数?都是多少?

方法1:

import itertools
from functools import reduce lyst = [1, 2, 3, 4, 5]
result = [] for el in itertools.permutations(lyst, 3):
temp = reduce(lambda x,y:x * 10 +y, el)
result.append(temp) print(f'总共有{len(result)}个互不相同且五重复数字的三位数,分别是:')
print(result)

方法2:

import copy
numbers = [1, 2, 3, 4, 5]
tri = []
for i in numbers:
d_u = copy.copy(numbers)
d_u.remove(i)
for j in d_u:
u = copy.copy(d_u)
u.remove(j)
for k in u :
tri.append(i * 100 + j * 10 + k) print(tri)
print(len(tri))

方法3:

import itertools
count = 0
for i in itertools. product([1,2,3,4,5], repeat=3):
if i[0] != i[1] and i[0] != i[2] and i[1] != i[2]:
print(i[0]*100 + i[1]*10 + i[2])
count += 1
print(count)

方法4:

firstNumber = [1, 2, 3, 4, 5]
count = 0
for i in firstNumber:
secondNumber = firstNumber[:]
secondNumber.remove(i)
for j in secondNumber:
thirdNumber = secondNumber[:]
thirdNumber.remove(j)
for k in thirdNumber:
print(str(i) + str(j) + str(k), end=",")
count += 1
print("一共有{}个数".format(count))

Python 3.X 练习集100题 01的更多相关文章

  1. Python 3.X 练习集100题 02

    企业发放的奖金根据利润提成.利润(I):低于或等于10万元时,奖金可提10%:高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万之间时,高 ...

  2. Python 3.X 练习集100题 03

    一个整数,它加上 100 后是一个完全平方数,再加上 168 又是一个完全平方数,请问该数是多少? import math for i in range(10000): n1 = math.sqrt( ...

  3. Python 3.X 练习集100题 05

    用 *号输出字母 C的图案 方法1: print(" ***** ") print(" ** * ") print(" ** ") prin ...

  4. Python 3.X 练习集100题 04

    输入某年某月某日,判断这一天是这一年的第几天? 方法1: import time test_time = input("请输入日期(年-月-日):") time_struct = ...

  5. python经典例题100题01

    [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? ans = [i*100+j*10+k for i in range(1, 5) for j in ra ...

  6. Python练习100题

    Python练习100题 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? #Filename:001.py cnt = 0#count the sum of res ...

  7. Python小白的数学建模课-05.0-1规划

    0-1 规划不仅是数模竞赛中的常见题型,也具有重要的现实意义. 双十一促销中网购平台要求二选一,就是互斥的决策问题,可以用 0-1规划建模. 小白学习 0-1 规划,首先要学会识别 0-1规划,学习将 ...

  8. Python练习题 026:求100以内的素数

    [Python练习题 026] 求100以内的素数. ------------------------------------------------- 奇怪,求解素数的题,之前不是做过了吗?难道是想 ...

  9. Go面试题精编100题

    Golang精编100题 选择题 1.   [初级]下面属于关键字的是()A. funcB. defC. structD. class 参考答案:AC 2.   [初级]定义一个包内全局字符串变量,下 ...

随机推荐

  1. K8S CoreDNS部署失败,发现的一个问题

    K8S CoreDNS部署失败,查看错误日志,提示如下 root >> kubectl get all --all-namespaces -o wide root >> kub ...

  2. Common Lisp : Symbol到底是什么

    主要参考: <Emacs之魂>(四) 包:

  3. redis的主从复制,哨兵值守

    环境: 主服务器:192.168.10.10    Centos 7  redis-5.0.4 从服务器:192.168.10.129  Centos 7  redis-5.0.4 从服务器:192. ...

  4. tkinter事件键盘绑定

    tkinter事件键盘绑定 from tkinter import * root=Tk() #创建一个框架,在这个框架中响应事件 frame=Frame(root, width=200,height= ...

  5. 一、NodeJS入门——准备工作(1)——NodeJS的安装

    目录 1.介绍 2.nodejs下载 3.nodejs安装 4.nodejs的简单实用 5.nodejs的经典入门:hello world 6.总结 1    介绍 这是一系列的内容主要是关于我在学习 ...

  6. 【python+selenium学习】Python常见错误之:IndentationError: unexpected indent

    初入python+selenium学习之路,总会遇到这样那样的问题.IndentationError: unexpected indent,这个坑我已经踏进数次了,索性记录下来.都知道Python对代 ...

  7. PowerShell:标记“&&”不是此版本中的有效语句分隔符

    将命令行语句中的 && 改为分号 ; 就好了,就是这么简单.

  8. 英语chiltonite葡萄石chiltonite单词

    葡萄石Chiltonite 1.葡萄石能够促进血液循环,具有美容养颜的功效,非常适合女性佩戴,可以增加个人魅力,还能加强事业财运,凝聚财富气场. 2.绿色光对应人体心轮,对心脏,肺脏有效用,内涵的磁石 ...

  9. linq to js 用法

    /** * 排序汇总 * */ var result = Enumerable.From(vm.productList).GroupBy("$.goods_id", null, f ...

  10. day 67 作业

    有红, 黄, 蓝三个按钮, 以及一个200X200px的矩形box, 点击不同的按钮, box的颜色会被切换为指定的颜色 <!DOCTYPE html> <html lang=&qu ...