From db74ade0234a40c2120ad5f2a41bee50ce13de02 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sat, 22 Apr 2023 19:51:01 +0800 Subject: 🤐 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test.py (limited to 'test.py') diff --git a/test.py b/test.py new file mode 100644 index 0000000..882ed9a --- /dev/null +++ b/test.py @@ -0,0 +1,18 @@ +import random + +# 生成一个随机整数 +num = random.randint(1, 10) +print(num) + +# 从序列中随机选择一个元素 +fruits = ['apple', 'banana', 'orange'] +fruit = random.choice(fruits) +print(fruit) + +# 打乱序列中元素的顺序 +random.shuffle(fruits) +print(fruits) + +# 生成一个 0 到 1 之间的随机小数 +r = random.uniform(1,2) +print('%.2f' % r) -- cgit v1.2.3-70-g09d2