This was a take home test question (which I mailed 20 minutes ago if Prof. Gruhn is ruthlessly scouring stackoverflow). First computer science course, Intro using Python. Using the book “Starting Out With Python 2nd Ed.” The test was basically on creating our own module libraries, reading and writing to a file, and try/except logic.
The first part asked to create a lottery mumber simulator. One that generated nonunique numbers, the other unique, non repeating numbers. Every answer I saw on here utilized lists, which is sadly the next chapter, and we were expressly forbidden from using them.
My code for this section:
import random
def ballPickerOne():
a = random.randint(1, 59)
b = random.randint(1, 59)
c = random.randint(1, 59)
d = random.randint(1, 59)
e = random.randint(1, 59)
f = random.randint(1, 35)
showNumbers(a,b,c,d,e,f)
def ballPickerTwo():
a = random.randrange(1,59,2)
b = random.randrange(1,59,3)
c = random.randrange(1,59,5)
d = random.randrange(1,59,7)
e = random.randrange(1,59,11)
f = random.randint(1,35)
showNumbers(a,b,c,d,e,f)
def showNumbers(a,b,c,d,e,f):
print("Your Numbers ...")
print()
print("Ball 1: ", a)
print("Ball 2: ", b)
print("Ball 3: ", c)
print("Ball 4: ", d)
print("Ball 5: ", e)
print("Red Ball: ", f)
print()
print("Good Luck")
We were required to use the showNumbers function to display the results, and in the format that would result from it. ballPickerTwo is the “unique” one, which I used prime number intervals in a failed attempt at uniqueness. I toyed with using a loop, but couldn’t figure out how to display the numbers generated using showNumbers.
This is a really tedious way of doing it, but it doesn’t use lists. It will pick random and unique values.