首页 > 解决方案 > 尝试使用用户输入作为起点从python 3范围内的列表中提取一定数量的数字

问题描述

x = input("How many numbers, between two and six?  ")
print("You have selected, " + x + " numbers!")
import random     # I would like to only print out the amount of numbers entered in the first line!!!
numbers = list(range(1,48))   # So if a user types six they get six random numbers and so on.
random.shuffle(numbers)
print(numbers)

标签: python

解决方案


你试过这个吗

import random

x = input("How many numbers, between two and six?  ")
print("You have selected, " + x + " numbers!")
li = [random.random() for x in range(int(x))]
print(li)

推荐阅读