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
Need help I’m new at this
|
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
Feb-13-2020, 02:17 PM
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...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
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.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()
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 methodThen 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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Feb-13-2020, 03:25 PM
Thanks i will work on it. Im confuse with the (created an instance and call the method)
Feb-13-2020, 06:34 PM
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
Feb-14-2020, 07:13 PM
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?
Feb-15-2020, 03:07 AM
Ok thanks
|
|