本文目錄一覽:
- 1、Python 生成隨機點坐標
- 2、python編程 編寫程序自動生成0到100間的一個隨機數,然後讓參與者輸入昵稱和數字,最後判斷誰猜得最准?
- 3、菜鳥,想做一個隨機點名軟件,抽取班上同學名字的那種。求方法,具體步驟,需要什麼軟件做。
Python 生成隨機點坐標
import random
import numpy as np
List = np.array([(0,0),(1,1),(1.6,1.8),(3,3)])
d = 0.5
def get_random(low,high):
return((high-low)*random.random()+low)
n = 0
while n100000:
x = get_random(0,3)
y = get_random(0,3)
rand_tuple = np.array([x,y])
tmp_dist = np.sqrt(np.sum(np.square(List-rand_tuple),axis = 1))
tmp_dist_bool = tmp_dist = d
if np.sum(tmp_dist_bool) == len(List):
print(x,y)
break
n += 1
if n==100000:
print(“After”,n,”tries,can’t get a random point!Check whether the problem has a solution!”)
python編程 編寫程序自動生成0到100間的一個隨機數,然後讓參與者輸入昵稱和數字,最後判斷誰猜得最准?
#!/usr/bin/python3
# -*- coding:utf-8 -*-
“””
@author:Storm_duck
@file :20200605-01.py
@time :2020/6/5 15:20
“””
“””
猜數字,看誰猜的最接近
“””
import random
def get_abs(rannum, ansnum):
return abs(ansnum – rannum)
if __name__ == “__main__”:
num = random.randint(1, 100)
adic = {}
lens = 0
while True:
choice = input(“What’s your name?,enter to quit:”)
if choice == “enter”:
break
if choice != “enter”:
answer = int(input(“What’s your guess(1-100):”))
lens += 1
if choice in adic.keys():
adic[choice] = answer
else:
adic.setdefault(choice, answer)
newlist = sorted(adic.items(), key = lambda kv: get_abs(num, kv[1]), reverse = False)
if newlist[0][1] != newlist[1][1]:
if num == newlist[0][1]:
print(“{} 厲害,數字就是{}:”.format(newlist[0][0], newlist[0][1]))
else:
print(“數字是{},猜的最接近的是:{}”.format(num, newlist[0][0]))
else:
temp = []
alist = list(zip(*newlist))[1]
t = alist[0]
for i in range(alist.count(t)):
temp.append(newlist[i][0])
astr = “,”.join(temp)
if num == t:
print(“{}都比較厲害,數字就是{}:”.format(astr, num))
else:
print(“數字是{},{}的答案相同,猜的最接近。”.format(num, astr))
菜鳥,想做一個隨機點名軟件,抽取班上同學名字的那種。求方法,具體步驟,需要什麼軟件做。
VB可以做,什麼軟件都可以,就是隨機數
要點名很容易,隨機抽取一名同學即可。但是點名以後的數據記錄和分析處理比較複雜。
你可以下載“倪大俠點名計分器”看一看,去“倪大俠軟件”官網下載最新版,不斷更新中。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/240917.html