Python Forum
List with Random Numbers
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List with Random Numbers
#1
For my homework, I need to make a lottery number generator, a program that generates a 7 digit lottery number, each digit generated on their own and between 0-9, then puts them in a list. By looking through my textbook and assignments done in class, I was able to piece this together:
def main():
    lottery_list = []
    import random
    random.seed(10)
    random1 = random.randint(0, 9)
    lottery_list.append(random1)
    random2 = random.randint(0, 9)
    lottery_list.append(random2)
    random3 = random.randint(0, 9)
    lottery_list.append(random3)
    random4 = random.randint(0, 9)
    lottery_list.append(random4)
    random5 = random.randint(0, 9)
    lottery_list.append(random5)
    random6 = random.randint(0, 9)
    lottery_list.append(random6)
    random7 = random.randint(0, 9)
    lottery_list.append(random7)

main()


print lottery_list
but I keep getting this error:
Error:
Traceback (most recent call last): File "C:/Users/Sami3_000/Documents/School/Intro to Program Logic and Design/Ch7Ex2.py", line 28, in <module> print lottery_list NameError: name 'lottery_list' is not defined
Why does it think I haven't defined it? And how can I improve my program?
Reply


Messages In This Thread
List with Random Numbers - by AnjyilLee - Oct-14-2017, 01:36 AM
RE: List with Random Numbers - by metulburr - Oct-14-2017, 02:52 AM
RE: List with Random Numbers - by AnjyilLee - Oct-14-2017, 03:17 AM
RE: List with Random Numbers - by buran - Oct-14-2017, 07:03 AM
RE: List with Random Numbers - by AnjyilLee - Oct-14-2017, 09:17 PM
RE: List with Random Numbers - by buran - Oct-14-2017, 09:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,486 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,090 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Return the sum of the first n numbers in the list. pav1983 3 4,192 Jun-24-2020, 03:37 AM
Last Post: deanhystad
  numbers in list - max value and average stewie 2 2,867 Apr-01-2020, 06:25 PM
Last Post: buran
  Random selection from list Mohsky 1 11,226 Mar-31-2020, 10:27 PM
Last Post: deanhystad
  Question about Sorting a List with Negative and Positive Numbers Than999 2 12,823 Nov-14-2019, 02:44 AM
Last Post: jefsummers
  Scaling random numbers within specific range schniefen 4 3,242 Oct-28-2019, 11:22 AM
Last Post: jefsummers
  How to Generate and Print An Array with Random Numbers in Python in the johnnynitro99293 14 9,777 Sep-20-2019, 11:56 AM
Last Post: ichabod801
  list of odd numbers cffiver2 2 5,249 Jul-12-2019, 09:46 AM
Last Post: perfringo
  CODE for Bubble sorting an unsorted list of 5 numbers. SIJAN 1 2,319 Dec-19-2018, 06:22 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020