def file_up(): """importing invoice2() function from Invoice_record which returns invoice file;f,'Cart','Cart_quantity' and is stored in f1,cart,cart_n respectively""" from Invoice_record import invoice2 f1, cart, cart_n = invoice2() # importing read_file.py which returns the 2D list stored in final_list and storing it in 'product' from read_file import read product = read() '''updating the inventory1.txt with the purchase of the product by reducing the quantity of the product bought from the quantity of product available in 'product' where the data is stored ''' for i in range(len(cart)): for k in range(len(product)): if cart[i] == product[k][0]: product[k][2] = int(product[k][2]) - int(cart_n[i]) '''writng the data of the 2D list 'product' in the file Inventory1.txt due to which theinventory is updated after the purchase''' f = open("Inventory1.txt", "w") for i in range(len(product)): for j in range(len(product[i])): f.write(str(product[i][j])) if j != 2: f.write(',') else: f.write("\n") f.close() # returning 'f1' which the invoice file and 'f' which is the updated inventory file return f1, f
def invoice1(): #two list to store the name and quantity of the product bought by the customer CART = [] CART_QUANTITY = [] #importing read_file having function read which returns the 2D list where the data of the inventory is stored and storing it in 'List' import read_file List = read_file.read() #using While loop to take input of the user for buying the products and storing its data in CART and CART_QUANTITY buy = "y" while buy == "y": sucess = False while sucess == False: prod = input("Enter the product you want to buy: ") prod_ = prod.lower() for i in range(len(List)): if prod_ == List[i][0].lower(): sucess = True if sucess == False: print("we don't have this product") sucess = False CART.append(prod_) suc = False while suc == False: try: num = int(input("Number of %s you want to buy: " % prod_)) for i in range(len(List)): if List[i][0] == prod_: if num < int(List[i][2]): CART_QUANTITY.append(num) suc = True elif num > int(List[i][2]): print("we have " + List[i][2] + " number of " + List[i][0]) except: print("Invalid input") suc = False success = False while success == False: buy1 = input("continue to buy (y/n): ") buy = buy1.lower() if buy == 'y': success = True elif buy == 'n': success = True #Returning the value of CART,CART_QUANTITY,List return CART, CART_QUANTITY, List
def coach( music, mode, ref_table ): # Decides of the following events according to the difficulties of the player if mode == 'basic': # Just waits for the player to press the right keys in order to generate the animation of the next 2 seconds fsampling, Notes = read_file.read_tlp(music) for sample in Notes: display.disp( Notes[sample], fsampling ) # The current structure of dis does not allow this contruction... error = error.get_error() elif mode == 'none': # Just displays the notes, regardless of the player's performance Notes, fsampling = read_file.read(music) display.disp(Notes, fsampling, 100, ref_table) else: print("Unavailable function at the moment") return exit_flag # The player needs to be able to quit the software at any moment
import sys import read_file import simulation from network import Network if __name__ == "__main__": with open('output.txt', 'w') as file: file.write('') simulation_file_name = sys.argv[1] network = Network([], []) read_file.read(network, simulation_file_name) nodes = network.nodes routers = network.routers simulation.start(network, sys.argv[2], sys.argv[3], sys.argv[4]) with open('output.txt', 'r') as file: print(file.read()) # for node in nodes: # print(node) # for router in routers: # print(router)
def main(filename, min_supp, min_conf): baskets = read(filename, 30000) # read such number of lines apriori = aPriori(baskets, min_supp, min_conf) output_file = open('output.txt', 'w') apriori.print_tuples(output_file) apriori.print_rules(output_file)
#main file of the program from where the program is executed. #Using 'while' loop to make the program run untill the user runs it continuesly run_program='yes' while run_program=='yes': #importing read_file.py which returns the 2D list stored in final_list and storing it in 'z' import read_file z=(read_file.read()) print("product Quantity Rate") #printing the number of products availabe in the inventory with their name for i in range(len(z)): print("%s "%z[i][0]+" %s"%str(z[i][2])+" %s"%str(z[i][1])) '''importing file_up() fucntion from the file file_update which returns file in which invoice is printed;f1 and updated Inventory1.txt;f ''' from file_update import file_up a=file_up() #using try:,except: for fault tolerance while asking the user to continue running the program success=False while success==False: run_program=input("Continue running the program(yes/no): " ) try: if run_program=="yes" or run_program=="no": success=True except: print("Invalid Input")
import read_file import json_wrapper import coursera import MySQLdb import sys if __name__ == '__main__': file_name = sys.argv[1] table_name = sys.argv[2] conn = MySQLdb.connect(host="localhost", user="******", passwd="Mdb4Learn", db="eLearning") coursera.create_table(conn, table_name) m = {} for row in read_file.read(file_name): # if row['key'] == 'user.video.lecture.action': # value = json_wrapper.loads(row['value']) # if value['type'] not in m: # m[value['type']] = '' # print(row) # continue if row['key'] == 'pageview': try: coursera.insert_table(conn, [ 'user_name', 'page_url', '`timestamp`', '`key`', '`session`' ], [ row['username'], row['page_url'], row['timestamp'], row['key'], row['session'] ], table_name)
temp[temp>1]=1 # 这里需要后面再考虑一下,将所有>1的值替换成1 ,现在是部分值计算略大于1,为1.0000004 # temp = np.fabs(temp) dn = R*np.arccos(temp) tt = dn**2/(re**2)*(-1) # 这个和上面一样 wn = np.exp(tt) wf = np.sum(wn*fn) w1 = np.sum(wn) bn = wf/w1 fbn[i,j] = bn fbn = xr.DataArray(fbn, coords=[y2, x2], dims=['latitude','longitude']) return fbn if __name__ == "__main__": data = read() pass
#遍历目录 path_real=path_download #if os.path.exists(path_download+'\\unzip'): # path_real = path_download+'\\unzip' #files=get_path.all_path(path_real) files=get_path.all_path(path_real) tags = [] file_number=0 for file in files: #print(file,file=f_log) extension = os.path.splitext(file)[1] if extension.lower()=='.html' or extension.lower()=='.txt': file_number+=1 print(file,file=f_log) print('后缀:', extension) html=read_file.read(file) #print(html) soup = BeautifulSoup(html, 'html.parser') if soup.html: childs=soup.html.descendants elif soup.body: childs=soup.body.descendants else: childs=[] for child in childs: if child.name not in tags: tags.append(child.name) print(tags,file=f_log) print('html tags number:',len(tags),file=f_log) if file_number>1: print('[备注]:存在多个文件!',file=f_log)
from read_file import read VERTIX_NUM = 264346 EDGES_NUM = 733846 data = read( "F:\Rutgers\\2nd Semester\DATA STRUCT & ALGS\Homework\hwk4\Q5\\NYC.txt") #data = [[1, 2], [2, 3], [1, 3], [1, 6], [4, 6], [4, 5], [3, 4], [3, 5]] class graph(): def __init__(self): self.graph = self.create_graph() self.trace = [False for i in range(VERTIX_NUM)] def create_graph(self): graph = [[] for i in range(VERTIX_NUM)] for edge in data: graph[edge[0] - 1].append(edge[1]) graph[edge[1] - 1].append(edge[0]) return graph def dfs(self, ver): print('check ', ver) self.trace[ver - 1] = True for child_ver in self.graph[ver - 1]: if not self.trace[child_ver - 1]: self.dfs(child_ver)
def dfs(self, ver, last): if not self.track: self.track = [None for i in range(len(self.graph))] self.track[ver] = True #print('current view ', ver) #print(self.track) # if ther is a cycle for vert in self.graph[ver]: if vert != last: #print('next ', vert) if not self.track[vert]: self.dfs(vert, ver) else: return False #print(ver, ' done') return True path = 'F:\Rutgers\\2nd Semester\DATA STRUCT & ALGS\Homework\hwk4\Q1\\data.txt' data = read(path) #data = [[0, 1], [0, 4], [3, 4], [2, 3], [0, 3]] new_graph = graph(data) graph = new_graph.create_graph() print(graph) res = new_graph.dfs(0, None) print(res)
from read_file import read VERTIX_NUM = 8 #EDGES_NUM = 15 INF = float('inf') data_A = read( 'F:\Rutgers\\2ndSemester\DATA STRUCT & ALGS\Homework\hwk4\Q6\\a.txt') data_B = read( 'F:\Rutgers\\2ndSemester\DATA STRUCT & ALGS\Homework\hwk4\Q6\\b.txt') class graph(): def __init__(self, data): self.data = sorted(data, key=lambda x: x[2]) self.disTo = [INF for i in range(VERTIX_NUM)] self.edgeTo = [None for i in range(VERTIX_NUM)] self.vertix = [False for i in range(VERTIX_NUM)] def normal_dij(self, ver=0): # initialize the disTo array self.disTo[ver] = 0 self.vertix[ver] = True for edge in self.data: if edge[0] == ver: self.disTo[edge[1]] = edge[2] self.edgeTo[edge[1]] = edge print('initial--------') print(self.disTo) print('----------------')
def ts_data(name,data,t): ''' 把三维的数据变成二维的了 xarray 中读数据 ''' h = data[name] # 读这个名字的数据 d = h.isel(time=t) # 在选择它这个时间 f = d.loc[y1[0]:y1[-1],x1[0]:x1[-1]] # 再选择它的坐标取中心点附近,半径为32网格的数据 return f h400 = ts_data(h40,data,t) h450 = ts_data(h45,data,t) h500 = ts_data(h50,data,t) h550 = ts_data(h55,data,t) vo400 = ts_data(vo40,data,t) vo450 = ts_data(vo45,data,t) vo500 = ts_data(vo50,data,t) vo550 = ts_data(vo55,data,t) height = [h400, h450, h500, h550] # 返回多个高度场数据 vorticity = [vo400, vo450, vo500, vo550] # 返回多个涡度场数据 # print(vo400) return height, vorticity if __name__ == "__main__": data = read() # 读取全部数据 m = 32;n=86 # 滤波前,由500hPa风场确定的大致中心位置,m是纬度,n是经度 d = 0.25 p0 = (m,n) data1, data2 = getdata(data,m,n,d) # 取得想要的初始范围内的数据,y纬度,x经度
import time import numpy as np from Plot import plotTSP from read_file import read,find_distance,find_segment_length from knapsack import knpsck_value_mat,knpsck_select_items from opt_2 import opt2 from greedy_1 import greedy # select points which maximizes happiness index for maximun capacity using knapsack # find travel time using opt2 # if travel time + time to visit places > maximum hours in hand (24) # decrese capacity by 1 and repeat data=read("data.xlsx") # column data # 0 x_cordinate # 1 y_cordinate # 2 happiness index # 3 time spent at that place(hours) capacity=24 # number of hours for a day=capacity value_mat=knpsck_value_mat(data,capacity) # value matrix using dynamic algorithm selected=knpsck_select_items(value_mat,capacity,data) points=data[selected][:] flag=0 while flag==0: opt2_result=opt2(points) best_distance=opt2_result[0] total_time=best_distance/50+points[:,3].sum() # speed is 50 km/hr if total_time<=24: