Skip to content

Instantly share code, notes, and snippets.

@imbyron
Last active December 31, 2015 03:28
Show Gist options
  • Save imbyron/7927349 to your computer and use it in GitHub Desktop.
Save imbyron/7927349 to your computer and use it in GitHub Desktop.
本程序会从1~n中随机取m个数,其中1<=m<=n
#!/usr/bin/python
#coding:utf-8
#author:byron
#blog:http://jiabin.tk
import random
def m_n():
print("本程序会从1~n中随机取m个数,1<=m<=n")
n = int(input("输入n的值:"))
m = int(input("输入m的值:"))
if 1 <= m <= n:
random_num = random.sample(list(range(1,n+1)),m)
print(random_num)
else:
print("="*40)
print('请确认1<=m<=n')
print('='*40)
m_n()
m_n()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment