Question:
So when you press 2 to start off with it’s fine but if you do it again it throws an error of TypeError: ‘str’ object is not callable
. Is there any fix?
Repl link:
https://replit.com/@SalladShooter/Scratchoff-Cycles-Lottery#main.py
Broken Code:
def leaderboard():
e.clear()
# Sort user array
users = dict(sorted(db["game"].items(), key=lambda a: a[1], reverse=True)).items()
# Format the users
leaderboard = ""
times = 1
for user, money in users:
leaderboard += f"| {times} - {user}: 🌀{BOLD}{money}{END} | \n"
times += 1
# Output
print(leaderboard)
enter()
e.clear()
print(f"\r{BOLD}Scratchoff Cycles Lottery!{END}")
print(f"You have {BOLD}🌀{money}{END}")
print()
print("What do you want to do?")
print(" |1| Buy Ticket")
print(" |2| Leaderboard")
choice = input("\n> ")
if choice == "1":
buyTicket()
elif choice == "2":
leaderboard()
All Code:
import random
import extrapy as e
import time
import sys
import os
import threading
from replit import db
db["game"] = db.get("game", {})
BLACK = "\033[0;30m"
RED = "\033[0;31m"
GREEN = "\033[0;32m"
BROWN = "\033[0;33m"
BLUE = "\033[0;34m"
PURPLE = "\033[0;35m"
CYAN = "\033[0;36m"
LIGHT_GRAY = "\033[0;37m"
DARK_GRAY = "\033[1;30m"
LIGHT_RED = "\033[1;31m"
LIGHT_GREEN = "\033[1;32m"
YELLOW = "\033[1;33m"
LIGHT_BLUE = "\033[1;34m"
LIGHT_PURPLE = "\033[1;35m"
LIGHT_CYAN = "\033[1;36m"
LIGHT_WHITE = "\033[1;37m"
BOLD = "\033[1m"
FAINT = "\033[2m"
ITALIC = "\033[3m"
UNDERLINE = "\033[4m"
BLINK = "\033[5m"
NEGATIVE = "\033[7m"
CROSSED = "\033[9m"
END = "\033[0m"
running = True
username = os.environ['REPL_OWNER']
beta = "True"
if beta == "True":
username = f"{GREEN}{BOLD}Beta Tester{LIGHT_WHITE}{END} {username}"
if os.environ['REPL_OWNER'] == "SalladShooter":
username = f"{RED}{BOLD}Owner{LIGHT_WHITE}{END} SalladShooter"
if username in db:
money = db[username]["money"]
takeAwayAmount = db[username]["takeAwayAmount"]
else:
db[username] = {"money": 100, "takeAwayAmount" : 5}
takeAwayAmount = db[username]["takeAwayAmount"]
money = db[username]["money"]
game = []
game.append(username)
# store for leaderboard
db["game"][username] = money
def enter():
input(f"\nPress | {BLUE}Enter{LIGHT_WHITE} | to continue...")
def scratch():
input(f"\nPress | {BLUE}Enter{LIGHT_WHITE} | to scratchoff...")
def bar():
print("------------------------")
def write(write):
for i in write:
sys.stdout.write(i)
sys.stdout.flush()
time.sleep(.05)
def titleBlink():
for _ in range(5):
text = f"{BOLD}Scratchoff Cycles Lottery!"
sys.stdout.write(f'\r{text}')
sys.stdout.flush()
time.sleep(0.5)
b = "Loading"
sys.stdout.write('\r' + ' ' * len(text))
sys.stdout.flush()
time.sleep(0.5)
print(f"{BOLD}Welcome To")
titleBlink()
running = False
print(f"\r{BOLD}Scratchoff Cycles Lottery!{END}")
bar()
enter()
e.clear()
def leaderboard():
e.clear()
# Sort user array
users = dict(sorted(db["game"].items(), key=lambda a: a[1], reverse=True)).items()
# Format the users
leaderboard = ""
times = 1
for user, money in users:
leaderboard += f"| {times} - {user}: 🌀{BOLD}{money}{END} | \n"
times += 1
# Output
print(leaderboard)
enter()
e.clear()
print(f"\r{BOLD}Scratchoff Cycles Lottery!{END}")
print(f"You have {BOLD}🌀{money}{END}")
print()
print("What do you want to do?")
print(" |1| Buy Ticket")
print(" |2| Leaderboard")
choice = input("\n> ")
if choice == "1":
buyTicket()
elif choice == "2":
leaderboard()
def printTicket(winNum, spot1, spot2, spot3, spot4, spot5, spot6, spot7, spot8):
global money, username, takeAwayAmount
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print("|-------| | // | // | // | // | |")
print("| | --------------------- |")
print("| // | | // | // | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
scratch()
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | // | // | // | // | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | // | // | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | // | // | // | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | // | // | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | // | // | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | // | // | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | {BOLD}{spot3}{END} | // | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | // | // | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | {BOLD}{spot3}{END} | {BOLD}{spot4}{END} | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | // | // | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | {BOLD}{spot3}{END} | {BOLD}{spot4}{END} | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | {BOLD}{spot5}{END} | // | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | {BOLD}{spot3}{END} | {BOLD}{spot4}{END} | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | {BOLD}{spot5}{END} | {BOLD}{spot6}{END} | // | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | {BOLD}{spot3}{END} | {BOLD}{spot4}{END} | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | {BOLD}{spot5}{END} | {BOLD}{spot6}{END} | // | // | |")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | {BOLD}{spot3}{END} | {BOLD}{spot4}{END} | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | {BOLD}{spot5}{END} | {BOLD}{spot6}{END} | {BOLD}{spot7}{END} | // | |")
print("| | --------------------- |")
print("-----------------------------------")
time.sleep(0.25)
e.clear()
e.clear()
print("___________________________________")
print("| Scratchoff Cycles Lottery |")
print("|-------|-------------------------|")
print("| Win # | _____________________ |")
print(f"|-------| | {BOLD}{spot1}{END} | {BOLD}{spot2}{END} | {BOLD}{spot3}{END} | {BOLD}{spot4}{END} | |")
print("| | --------------------- |")
print(f"| {BOLD}{winNum}{END} | | {BOLD}{spot5}{END} | {BOLD}{spot6}{END} | {BOLD}{spot7}{END} | {BOLD}{spot8}{END} | |")
print("| | --------------------- |")
print("-----------------------------------")
winMoney = 0
if spot1 == winNum:
winMoney += random.randint(10,5000)
if spot2 == winNum:
winMoney += random.randint(10,5000)
if spot3 == winNum:
winMoney += random.randint(10,5000)
if spot4 == winNum:
winMoney += random.randint(10,5000)
if spot5 == winNum:
winMoney += random.randint(10,5000)
if spot6 == winNum:
winMoney += random.randint(10,5000)
if spot7 == winNum:
winMoney += random.randint(10,5000)
if spot8 == winNum:
winMoney += random.randint(10,5000)
if winMoney >= 5000:
print(f"{BOLD}You hit the {YELLOW}JACKPOT{LIGHT_WHITE}!{END}")
takeAwayAmount = takeAwayAmount * 1.5
db[username]["takeAwayAmount"] = takeAwayAmount
print(f"You won {BOLD}🌀{winMoney}{END}!")
money += winMoney
winMoney = 0
db[username]["money"] = money
db["game"][username] = money
enter()
e.clear()
print(f"\r{BOLD}Scratchoff Cycles Lottery!{END}")
print(f"You have {BOLD}🌀{money}{END}")
print()
print("What do you want to do?")
print(" |1| Buy Ticket")
print(" |2| Leaderboard")
choice = input("\n> ")
if choice == "1":
buyTicket()
elif choice == "2":
leaderboard()
def buyTicket():
global money, username, takeAwayAmount
money -= takeAwayAmount
db[username]["money"] = money
db["game"][username] = money
e.clear()
winNum = random.randint(1,99)
spot1 = random.randint(1,99)
spot2 = random.randint(1,99)
spot3 = random.randint(1,99)
spot4 = random.randint(1,99)
spot5 = random.randint(1,99)
spot6 = random.randint(1,99)
spot7 = random.randint(1,99)
spot8 = random.randint(1,99)
if winNum < 10:
winNum = f"0{winNum}"
if spot1 < 10:
spot1 = f"0{spot1}"
if spot2 < 10:
spot2 = f"0{spot2}"
if spot3 < 10:
spot3 = f"0{spot3}"
if spot4 < 10:
spot4 = f"0{spot4}"
if spot5 < 10:
spot5 = f"0{spot5}"
if spot6 < 10:
spot6 = f"0{spot6}"
if spot7 < 10:
spot7 = f"0{spot7}"
if spot8 < 10:
spot8 = f"0{spot8}"
printTicket(winNum, spot1, spot2, spot3, spot4, spot5, spot6, spot7, spot8)
class Game:
print(f"\r{BOLD}Scratchoff Cycles Lottery!{END}")
print(f"You have {BOLD}🌀{money}{END}")
print()
print("What do you want to do?")
print(" |1| Buy Ticket")
print(" |2| Leaderboard")
choice = input("\n> ")
if choice == "1":
buyTicket()
elif choice == "2":
leaderboard()
Game()