Feb-13-2020, 02:13 PM
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
[
and ]
are visible when you print that list. Just print the element of the list, not the list itself.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.frame=(-15+i*70,400,60,70) b.border_width= 1.5 b.border_color = 'black' b.title = str(i) b.background_color='lightgray' b.action = b_action v.add_subview(b) b.tint_color = 'red' l = ui.Label( alignment=ui.ALIGN_CENTER, bg_color='white', border_color='black', border_width=1.5, frame=(50, 100, 100, 50), name='l', font=('Copperplate', 18)) l.text_color='red' l.number_of_lines = (2) l.frame = (12,100,350,80) v.add_subview(l) v.present('screen') 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) a.sort() return a if __name__ == '__main__': Function()
str(Lottery.lotteryLogic(1, 46, 6)
', '.join(Lottery.lotteryLogic(1, 46, 6))
self
as first argument. Probably draw()
would be better name for this methodui
module and cannot advise, but creating gui in a function is bit odd.