def save(data, names): import modules folderDirectory = "data/" for i in range(modules.panjang(names)): # Melakukan looping berdasarkan panjang array names name = str(folderDirectory + input("Masukkan nama file " + str(names[i]) + " :")) # input nama file csv writeFile(name, data[i]) # Memanggil fungsi writeFile print('Data berhasil disimpan!')
def signup(x): unameAvailable = False global user_data new_data = [0 for i in range(7)] i = 0 while (role == "Admin"): for i in new_data: new_data[0] = input("Masukkan nama pemain: ") new_data[1] = input("Masukkan tanggal lahir pemain: ") new_data[2] = input("Masukkan tinggi badan pemain (cm): ") new_data[3] = input("Masukkan username pemain: ") while i < modules.panjang(x) and not (unameAvailable): if x[i][3] == new_data[3]: unameAvailable = True print( "Username sudah digunakan, silahkan masukan username lain." ) new_data[3] = input("Masukkan username pemain: ") else: i += 1 new_data[4] = input("Masukkan password pemain: ") new_data[5] = ("pemain") new_data[6] = ("0") print("Selamat menjadi pemain,", new_data[0], ". Selamat bermain.") user_data = user_data + [new_data] return user_data print("Maaf anda bukan Admin !")
def save(data, names, currentUser): folderDirectory = "data/" # Melakukan looping berdasarkan panjang array names for i in range(modules.panjang(names)): name = str(folderDirectory + names[i]) writeFile(name, data[i]) print("Your progress on character", currentUser[1], "has been saved")
def signup(user_data, currentUser): import modules, B01_hash unameAvailable = False # Inisiasi role = currentUser[5] new_data = [0 for i in range (7)] i = 0 if (role == "Admin"): # Validasi role apakah Admin atau Pemain new_data[0] = input("Masukkan nama pemain: ") # Memberikan input nama pemain new_data[1] = input("Masukkan tanggal lahir pemain: ") # Memberikan input tanggal lahir pemain new_data[2] = input("Masukkan tinggi badan pemain (cm): ") # Memberikan input tinggi pemain dalam cm new_data[3] = input("Masukkan username pemain: ") # Memberikan input username pemain while i < (modules.panjang(user_data)) and not(unameAvailable): # Program terus mengulang pada saat panjang array user_data kurang dari i dan unameAvailable False if user_data[i][3] == new_data[3]: # Jika username sudah digunakan print("Username sudah digunakan, silahkan masukan username lain.") new_data[3] = input("Masukkan username pemain: ") else: i += 1 new_data[4] = B01_hash.hashPassword(input("Masukkan password pemain: ")) # Memberika input password new_data[5] = ("Pemain") new_data[6] = ("0") print("Selamat menjadi pemain,",new_data[0],". Selamat bermain.") user_data = user_data + [new_data] # array new_data ditambahkan kedalam array user_data return user_data else: print("Maaf anda bukan Admin !") # x = [(0), (0), (0)] # currentUser = [" $NOUSER", " %NOUSER", " $NOUSER", " $NOUSER", " $NOUSER", "Admin", " $NOUSER"] # signup(x, currentUser)
def showTicket(tiket_data, currentUser, wahana_data): ''' tiket_data = Username,Tanggal_Pembelian,ID_Wahana,Jumlah_Tiket wahan_data = ID_Wahana,Nama_Wahana,Harga_Tiket,Batasan_Umur,Batasan_Tinggi ''' import modules userTickets = [] for row in tiket_data: if row[0] == currentUser[3]: userTickets = modules.addToArray(userTickets, row) userTickets = modules.strSort(userTickets, 2, "ascending") print("Riwayat: ") if modules.panjang(userTickets) != 0: selected = userTickets[0] currentCount = 0 else: print() return for tiket in userTickets: if tiket[2] == selected[2]: currentCount += int(tiket[3]) else: rideIndex = modules.search(selected[2], 0, wahana_data, 'index') rideName = wahana_data[rideIndex][1] print(selected[2], rideName, currentCount, sep=" | ") lastcount = currentCount currentCount = 0 selected = tiket rideIndex = modules.search(selected[2], 0, wahana_data, 'index') rideName = wahana_data[rideIndex][1] print(tiket[2], rideName, lastcount, sep=" | ")
def showBestWahana(pembelian_data, wahana_data): ''' pembelian_data = Username,Tanggal_Pembelian,ID_Wahana,Jumlah_Tiket wahana_data = ID_Wahana,Nama_Wahana,Harga_Tiket,Batasan_Umur,Batasan_Tinggi ''' import modules pembelian_data = modules.strSort(pembelian_data, 2, "ascending") pembelian_wahana = [] if modules.panjang(pembelian_data) != 0: selected = pembelian_data[1] currentCount = 0 else: print() return # Menyimpan jumlah wahana wahanaCount = 0 for data in pembelian_data: if data != pembelian_data[0]: # Wahana sudah diurutkan, mengecek jika data mengenai sama dengan wahana yang sedang di proses if data[2] == selected[2]: # Menambahkan ke total penjualan tiket untuk wahana tersebut currentCount += int(data[3]) else: # Memberi input baru pembelian data # Input baru berisi ID Wahana dan jumlah tiket total (currentCount) newEntry = [selected[2], currentCount] pembelian_wahana = modules.addToArray(pembelian_wahana, newEntry) wahanaCount += 1 selected = data currentCount = int(selected[3]) # Menambahkan data terakhir newEntry = [data[2], int(currentCount)] pembelian_wahana = modules.addToArray(pembelian_wahana, newEntry) # Mengurutkan data pembelian_wahana = modules.intSort(pembelian_wahana, 1, "descending") # Memberi output 3 terbaik count = 0 while count <= 2 and count <= wahanaCount: # Mencari nama wahana indexWahana = modules.search(pembelian_wahana[count][0], 0, wahana_data, "index") namaWahana = wahana_data[indexWahana][1] #Display output print(count + 1, pembelian_wahana[count][0], namaWahana, pembelian_wahana[count][1], sep=" | ") count += 1