1. python里怎樣批量生成變數,如生成100個變數x001~x100
為什麼需要生成100個變數呢?直接用字典不就行了?我想不出要單獨生成100個變數的理由。
2. python編寫100組不重復的六位數整數並寫入文件中
import numpy as np
num_list = np.random.randint(100000, 999999, 100)
# 然後這個num_list就是一個包含了100個隨機六位整數的列表,可以拿去寫入文件等等
3. python編程 編寫程序自動生成0到100間的一個隨機數,然後讓參與者輸入昵稱和數字,最後判斷誰猜得最准
#!/usr/bin/python3# -*- coding:utf-8 -*-"""@author:Storm_ck@file :20200605-01.py@time :2020/6/5 15:20""""""猜數字,看誰猜的最接近"""import randomdef get_abs(rannum, ansnum):return abs(ansnum - rannum)if __name__ == "__main__":num = random.randint(1, 100)adic = {}lens = 0while True:choice = input("What's your name?,enter to quit:")if choice == "enter":breakif choice != "enter":answer = int(input("What's your guess(1-100):"))lens += 1if choice in adic.keys():adic[choice] = answerelse: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))
4. python快速自動生成100g文件至手機上
答:程序出錯誠心為你解答,給個好評哦親,謝謝啦
5. 如何實現30000份文件批量生成用Python完成
Num = 2 #定義批量創建文件的數量
def text_create(name):
path = "C:\Users\Administrator\Desktop\" # 新創建的txt文件的存放路徑,可以自己改
full_path = path + name + '.txt' # 也可以創建別的文件
file = open(full_path, 'w')
file.close()
for i in range(Num):
text_create('mytxtfile'+str(i))
#縮進如下:
6. 有沒有python好的大佬 自動生成1-10數組怎麼弄啊
這個是列表。如果生成的隨機數不在列表中就添加進去。
import random
def union(number):
array=[]
for i in range(number):
while True:
tmp = random.randrange(1,100)
if tmp not in array:
array.append(tmp)
break
return array
print (union(10))
7. python編寫一個程序將隨機產生的100個整數寫入一個文件。文件中的整數由空格分隔。