Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Need help I’m new at this
I have a number generator app I’m building. When i get the return i get the numbers looking like this. [2, 3, 5, 6] how can i get only the numbers without the [ ] marks. Any help will be appreciated
you get a list of numbers and [ and ] are visible when you print that list. Just print the element of the list, not the list itself.
Of course showing your code would help to help you more...
Here is my code:

import random
import ui

def Function():
    v = ui.View()
    v.background_color = 'white'
    v.background_frame = '0, 0, w, h'
    for i in range(1,5):
        b = ui.Button()
        b.border_width= 1.5
        b.border_color = 'black'
        b.title = str(i)
        b.action = b_action
        b.tint_color = 'red'
    l = ui.Label(
    frame=(50, 100, 100, 50),
    name='l', font=('Copperplate', 18))
    l.number_of_lines = (2)
    l.frame = (12,100,350,80)
def b_action(sender):
    x = sender.title
    l = sender.superview['l']
    if x == '1': l.text = 'Megabucks   '+str(Lottery.lotteryLogic (1, 46, 6))
    elif x == '2': l.text = 'Lucky 4 Life    '+str(Lottery.lotteryLogic (1, 48, 5))+str(Lottery.lotteryLogic (1, 18, 1))
    elif x == '3': l.text = 'Powerball   '+str(Lottery.lotteryLogic (1, 69, 5))+str(Lottery.lotteryLogic (1, 26, 1))
    elif x == '4': l.text = 'Mega Mil   '+str(Lottery.lotteryLogic (1, 70, 5))+str(Lottery.lotteryLogic(1, 25, 1))

class Lottery:
    def __init__( self ): 
        self.a = 0

    def lotteryLogic(startPosi, endPosi, interateNumber):
        a = random.sample (range(startPosi, endPosi), interateNumber)
        return a

if __name__ == '__main__':
buran wrote Feb-13-2020, 02:47 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
instead of str(Lottery.lotteryLogic(1, 46, 6)
you can do ', '.join(Lottery.lotteryLogic(1, 46, 6))

However, there is much bigger problem in your code - Lottery.lotteryLogic
This should be an instance method, and you should pass self as first argument. Probably draw() would be better name for this method
Then create an instance and call the method.
You may pass max value when instantiate the object and only call the draw method with number of balls you want
Finally curently you can get repeating numbers (i.e. drawing one number, that is already in the previous 5)

I don't know ui module and cannot advise, but creating gui in a function is bit odd.
Thanks i will work on it. Im confuse with the (created an instance and call the method)
Im stuck if there’s any way you can help me set this up. Im learning and want to be good at it but running to some stuff i cant fix. Sorry for the inconvenience
Have you taken on a project that's too big right now? If you don't understand fundamental things like "creating an instance", perhaps you need to spend more time on the basics?
Ok thanks

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)