Skip to main content
Tweeted twitter.com/StackCodeReview/status/1030967946049449984
Put powerball scenariors after non-powerballs, set m to 0 before powerball scenarios.
Source Link
import random
    choice = raw_input("Do you want to randomly generate numbers, or pick them? (Enter 'R' for random, 'P' for pick.")
    if choice == ('R'):
      one = random.randint(1,69)
      two = random.randint(1,69)
      three = random.randint(1,69)
      four = random.randint(1,69)
      five = random.randint(1,69)
      pball = random.randint(1,26)
    elif choice == ('P'):
      one = int(raw_input("Please pick your 1st number, between 1 and 69."))
      two = int(raw_input("Please pick your 2nd number, between 1 and 69."))
      three = int(raw_input("Please pick your 3rd number, between 1 and 69."))
      four = int(raw_input("Please pick your 4th number, between 1 and 69."))
      five = int(raw_input("Please pick your 5th number, between 1 and 69."))
      pball = int(raw_input("Please pick your Powerball number, between 1 and 26."))
      if ((one or two or three or four or five) > 69) or pball > 26 or ((one or two or three or four or five or pball) < 1): #In case the entered numbers are too high or too low.
        print "Please choose a number between 1 and 69."
    elif choice != ('R' or 'P'): #In case invalid input is given.
      print "Please enter either 'R' for random or 'P' for picking."
    human = [one, two, three, four, five, pball]
    print human
    #August 15, 2018 Powerball
    real = [12,15,28,47,48,16]
    jackpot = 40000000
    multiplier = 2
    def powerball(human,real,jackpot,multiplier):
      x = raw_input("Do you want to buy the multiplier for $1? ('Y' or 'N')")
      if x == 'Y':
        pass
      elif x == 'N':
        multiplier = 1
      p = 0 #Prize
      i = 0 #Index
      m = 0 #Matches
      if human[5] == real[5]: #If you only get the powerball right.
        p = 4
      for i in range(0,5): #If you only get normal numbers along with, theno powerball.
        if (human[i] in real) and (human[5] == real[5]):
          m += 1
        i += 1
        if m == 1:
          p = 4
        elif m == 23:
          p = 7
        elif m == 34:
          p = 100
        elif m == 45:
          p = 500001000000
        elif m == 5:
          p = jackpot0
      for i in range(0,5): #If you only get normal numbers, noalong with the powerball.
        if (human[i] in real:
) and (human[5] == real[5]):
      m += 1
        i += 1
        if m == 31:
      p = 4
    pelif =m 7== 2:
      p = 7
    elif m == 43:
          p = 100
        elif m == 54:
      p = 50000
    elif pm === 10000005:
      p *== multiplierjackpot
  p *= multiplier
  if p > 0:
        return "Congratulations, you won $%s!" % (p)
      elif p == 0:
        return "Sorry, you didn't win anything, try again next time."
    print powerball(human, real, jackpot, multiplier)
import random
    choice = raw_input("Do you want to randomly generate numbers, or pick them? (Enter 'R' for random, 'P' for pick.")
    if choice == ('R'):
      one = random.randint(1,69)
      two = random.randint(1,69)
      three = random.randint(1,69)
      four = random.randint(1,69)
      five = random.randint(1,69)
      pball = random.randint(1,26)
    elif choice == ('P'):
      one = int(raw_input("Please pick your 1st number, between 1 and 69."))
      two = int(raw_input("Please pick your 2nd number, between 1 and 69."))
      three = int(raw_input("Please pick your 3rd number, between 1 and 69."))
      four = int(raw_input("Please pick your 4th number, between 1 and 69."))
      five = int(raw_input("Please pick your 5th number, between 1 and 69."))
      pball = int(raw_input("Please pick your Powerball number, between 1 and 26."))
      if ((one or two or three or four or five) > 69) or pball > 26 or ((one or two or three or four or five or pball) < 1): #In case the entered numbers are too high or too low.
        print "Please choose a number between 1 and 69."
    elif choice != ('R' or 'P'): #In case invalid input is given.
      print "Please enter either 'R' for random or 'P' for picking."
    human = [one, two, three, four, five, pball]
    print human
    #August 15, 2018 Powerball
    real = [12,15,28,47,48,16]
    jackpot = 40000000
    multiplier = 2
    def powerball(human,real,jackpot,multiplier):
      x = raw_input("Do you want to buy the multiplier for $1? ('Y' or 'N')")
      if x == 'Y':
        pass
      elif x == 'N':
        multiplier = 1
      p = 0 #Prize
      i = 0 #Index
      m = 0 #Matches
      if human[5] == real[5]: #If you only get the powerball right.
        p = 4
      for i in range(0,5): #If you get normal numbers along with the powerball.
        if (human[i] in real) and (human[5] == real[5]):
          m += 1
        i += 1
        if m == 1:
          p = 4
        elif m == 2:
          p = 7
        elif m == 3:
          p = 100
        elif m == 4:
          p = 50000
        elif m == 5:
          p = jackpot
      for i in range(0,5): #If you only get normal numbers, no powerball.
        if human[i] in real:
          m += 1
        i += 1
        if m == 3:
          p = 7
        elif m == 4:
          p = 100
        elif m == 5:
          p = 1000000
      p *= multiplier
      if p > 0:
        return "Congratulations, you won $%s!" % (p)
      elif p == 0:
        return "Sorry, you didn't win anything, try again next time."
    print powerball(human, real, jackpot, multiplier)
import random
choice = raw_input("Do you want to randomly generate numbers, or pick them? (Enter 'R' for random, 'P' for pick.")
if choice == ('R'):
  one = random.randint(1,69)
  two = random.randint(1,69)
  three = random.randint(1,69)
  four = random.randint(1,69)
  five = random.randint(1,69)
  pball = random.randint(1,26)
elif choice == ('P'):
  one = int(raw_input("Please pick your 1st number, between 1 and 69."))
  two = int(raw_input("Please pick your 2nd number, between 1 and 69."))
  three = int(raw_input("Please pick your 3rd number, between 1 and 69."))
  four = int(raw_input("Please pick your 4th number, between 1 and 69."))
  five = int(raw_input("Please pick your 5th number, between 1 and 69."))
  pball = int(raw_input("Please pick your Powerball number, between 1 and 26."))
  if ((one or two or three or four or five) > 69) or pball > 26 or ((one or two or three or four or five or pball) < 1): #In case the entered numbers are too high or too low.
    print "Please choose a number between 1 and 69."
elif choice != ('R' or 'P'): #In case invalid input is given.
  print "Please enter either 'R' for random or 'P' for picking."
human = [one, two, three, four, five, pball]
print human
#August 15, 2018 Powerball
real = [12,15,28,47,48,16]
jackpot = 40000000
multiplier = 2
def powerball(human,real,jackpot,multiplier):
  x = raw_input("Do you want to buy the multiplier for $1? ('Y' or 'N')")
  if x == 'Y':
    pass
  elif x == 'N':
    multiplier = 1
  p = 0 #Prize
  i = 0 #Index
  m = 0 #Matches
  if human[5] == real[5]: #If you only get the powerball right.
    p = 4
  for i in range(0,5): #If you only get normal numbers, no powerball.
    if human[i] in real:
      m += 1
    i += 1
    if m == 3:
      p = 7
    elif m == 4:
      p = 100
    elif m == 5:
      p = 1000000
  m = 0
  for i in range(0,5): #If you get normal numbers along with the powerball.
    if (human[i] in real) and (human[5] == real[5]):
      m += 1
    i += 1
    if m == 1:
      p = 4
    elif m == 2:
      p = 7
    elif m == 3:
      p = 100
    elif m == 4:
      p = 50000
    elif m == 5:
      p = jackpot
  p *= multiplier
  if p > 0:
    return "Congratulations, you won $%s!" % (p)
  elif p == 0:
    return "Sorry, you didn't win anything, try again next time."
print powerball(human, real, jackpot, multiplier)
Source Link

Python 2.7 Powerball Game

This game allows one to either pick their own lottery numbers or have them generated and checks them with the most recent numbers, jackpot, and multiplier. I use concepts such as random, for loops, raw_input, and logic. I would it appreciated if it were reviewed by someone more experienced.

import random
    choice = raw_input("Do you want to randomly generate numbers, or pick them? (Enter 'R' for random, 'P' for pick.")
    if choice == ('R'):
      one = random.randint(1,69)
      two = random.randint(1,69)
      three = random.randint(1,69)
      four = random.randint(1,69)
      five = random.randint(1,69)
      pball = random.randint(1,26)
    elif choice == ('P'):
      one = int(raw_input("Please pick your 1st number, between 1 and 69."))
      two = int(raw_input("Please pick your 2nd number, between 1 and 69."))
      three = int(raw_input("Please pick your 3rd number, between 1 and 69."))
      four = int(raw_input("Please pick your 4th number, between 1 and 69."))
      five = int(raw_input("Please pick your 5th number, between 1 and 69."))
      pball = int(raw_input("Please pick your Powerball number, between 1 and 26."))
      if ((one or two or three or four or five) > 69) or pball > 26 or ((one or two or three or four or five or pball) < 1): #In case the entered numbers are too high or too low.
        print "Please choose a number between 1 and 69."
    elif choice != ('R' or 'P'): #In case invalid input is given.
      print "Please enter either 'R' for random or 'P' for picking."
    human = [one, two, three, four, five, pball]
    print human
    #August 15, 2018 Powerball
    real = [12,15,28,47,48,16]
    jackpot = 40000000
    multiplier = 2
    def powerball(human,real,jackpot,multiplier):
      x = raw_input("Do you want to buy the multiplier for $1? ('Y' or 'N')")
      if x == 'Y':
        pass
      elif x == 'N':
        multiplier = 1
      p = 0 #Prize
      i = 0 #Index
      m = 0 #Matches
      if human[5] == real[5]: #If you only get the powerball right.
        p = 4
      for i in range(0,5): #If you get normal numbers along with the powerball.
        if (human[i] in real) and (human[5] == real[5]):
          m += 1
        i += 1
        if m == 1:
          p = 4
        elif m == 2:
          p = 7
        elif m == 3:
          p = 100
        elif m == 4:
          p = 50000
        elif m == 5:
          p = jackpot
      for i in range(0,5): #If you only get normal numbers, no powerball.
        if human[i] in real:
          m += 1
        i += 1
        if m == 3:
          p = 7
        elif m == 4:
          p = 100
        elif m == 5:
          p = 1000000
      p *= multiplier
      if p > 0:
        return "Congratulations, you won $%s!" % (p)
      elif p == 0:
        return "Sorry, you didn't win anything, try again next time."
    print powerball(human, real, jackpot, multiplier)