• Welcome to the new forums! Server IP: smp.hometownmc.com
Hello There, Guest! Login Register


Thread Rating:
  • 5 Vote(s) - 4.6 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ask a stupid question, get a stupid answer
Listen to better music.

Why doesn't my code work?

import random, string

def randomword(length):
   return ''.join(random.choice(string.ascii_lowercase) for i in range(length))

def CheckTitle(name):
   if name in clubChampions:
      return str('[Champion] ' + name)
   elif name in grandMasters:
      return str('[GrandMaster] ' + name)
   elif name in masters:
      return str('[Master] ' + name)
   else:
      return name
   
def updatetitlelist():
   global clubChampions
   clubChampions = []
   global grandMasters
   grandMasters = []
   global masters
   masters = []
   users.sort(reverse = True)
   running = True
   currentuser = 0
   currentscore = users[0][0]
   while running:
      if users[currentuser][0] == currentscore:
         clubChampions.append(users[currentuser][1])
         currentuser += 1
      else:
         running = False
   for x in range(0, round((len(users) - 1) / 10)):
      grandMasters.append(users[x + 1][1])
      currentscore = users[x + 1][0]
   running = True
   currentuser = round((len(users) - 1) / 10) + 1
   while running:
      if users[currentuser][0] == currentscore:
         grandMasters.append(users[currentuser][1])
         currentuser += 1
      else:
         running = False
   for x in range(0, round((len(users) - 1) / 5)):
      masters.append(users[x + 1][1])
      currentscore = users[x + 1][0]
   running = True
   currentuser = round((len(users) - 1) / 5) + 1
   while running:
      if users[currentuser][0] == currentscore:
         masters.append(users[currentuser][1])
         currentuser += 1
      else:
         running = False
      
def PrintLeaderBoard():
   prevScore = ''
   prevRank = 1
   rank = 1
   for x in users:
       if x[0] == prevScore and prevRank < 10:
           print('    ',CheckTitle(x[1]),x[0])
       elif x[0] == prevScore:
           print('     ',CheckTitle(x[1]),x[0])
       else:
           print(rank,': ',CheckTitle(x[1]),x[0])
           prevRank = rank
       prevScore = x[0]
       rank += 1

users = []
for x in range(101):
    users.append([str(random.randint(1900,2100)),randomword(3)])
users.sort(reverse = True)
print(users)
print()
print()
print('Current leaderboard:')
updatetitlelist()
PrintLeaderBoard()

Just kidding, it works xDD
[Image: P4HqY8y.png]
 
Reply
  


Messages In This Thread
RE: ask a stupid question, get a stupid answer - by Penguin - 08-12-2016, 09:05 PM

Forum Jump:


Browsing: 21 Guest(s)