Hi im having trouble chaning the format of the generated raffles as it appears it stands like this Aqua 49250097 and what im trying to achive is something like this Aqua 4925 0097 and im not getting any raffle beging with 0 for example like blue 0223 4773. heres my code
from sqlalchemy import *
import random
engine = create_engine('sqlite:///raffle.db')
metadata = MetaData(bind=engine)
raffles_table = Table('raffles', metadata,
Column('id', Integer, primary_key=True),
Column('email', String(40)),
Column('raffle_color', String(40)),
Column('raffle_ticket', Integer),
)
# create tables in database
metadata.create_all(checkfirst=True)
# create a database connection
conn = engine.connect()
def add_raffles():
email = input("Please enter your email address:")
num_tickets = int(input("How many tickets do you want:"))
for i in range(num_tickets):
ins_raffle = raffles_table.insert()
colors = ['blue','Pink','Plum','Aqua','Navy','Grey','Rose','Ruby','Teal','Gold','Jade','Lime']
color = random.choice(colors)
ticket = random.randrange(10 ** 8)
new_raffle = ins_raffle.values(email = email, raffle_color = color, raffle_ticket = ticket)
# add raffle to database by executing SQL
conn.execute(new_raffle)
print(color + " " + str(ticket))
def select_winner():
winner_query = raffles_table.select().order_by(func.random()).limit(2)
winner = conn.execute(winner_query)
for row in winner:
print("The winner is:" + row['email'])
print("The winning raffle is:" + row['raffle_color'] +" " + str(row['raffle_ticket']))
Aucun commentaire:
Enregistrer un commentaire