I need help changing bits of my code so my raffles come up bit like this Aqua 0172 6644.heres my code.it should be made up of 8 random digits.how can i change it so its more like this grey 8833 1989,soz for typing stackover needs more discription
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(1000,9999)
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