from sys import exit
from sys import argv
import random
script, second = argv
print "The script is: ", script
print "The second argument is: ", second
print "\n"
def play_ball():
print "Welcome to the big leagues!"
print "You are now a player on the Yankees."
print "What is your name and position?"
print "\n"
name = raw_input("Name?: ")
position = raw_input("Position?: ")
print "\n"
print "Great, so your name is %s and your position is %s." % (name, position)
print "\n"
decision()
def decision():
print "Would you like to hit or pitch?"
choice = raw_input("> ")
if choice.lower() == "hit":
batters_box()
elif choice.lower() == "pitch":
pitchers_mound()
else:
print "I don't know what that means"
decision()
def batters_box():
score = 0
outs = 0
count_1 = [0, 0]
while True:
print "\n"
print "Get ready for the pitch!"
print "Choose a number between 1 and 4."
guess = raw_input("> ")
try:
pitch_guess = int(guess)
except ValueError:
print "%s is not a number. Try again." % guess
batters_box() ##this is a bug##
ball = random.randint(1, 4)
decider = random.randint(1, 10)
if pitch_guess == ball and decider == 10:
print "You hit a homerun!"
score += 5
print "Your score is: ", score
count_1[:] = [0, 0]
elif pitch_guess == ball and 10 > decider >= 8:
print "You hit a triple!"
score += 3
print "Your score is: ", score
count_1[:] = [0, 0]
elif pitch_guess == ball and 8 > decider >= 6:
print "You hit a double!"
score += 2
print "Your score is: ", score
count_1[:] = [0 ,0]
elif pitch_guess == ball and 6 > decider >= 3:
print "You hit a single!"
score += 1
print "Your score is: ", score
count_1[:] = [0, 0]
elif pitch_guess == ball and 3 > decider >= 2:
print "That's a ball."
count_1[0] += 1
print "The count is: ", count_1
if count_1[0] == 4:
print "That's a walk. Take your base."
score += 1
print "Your score is: ", score
count_1[:] = [0, 0]
else:
print "That's a strike!"
count_1[1] += 1
print "The count is: ", count_1
if count_1[1] == 3:
print "That's strike 3, you're out!"
outs +=1
print "\n You now have %d outs: " % outs
break
else:
continue
count_2 = [0, 0]
while True:
print "\n"
print "Get ready for the pitch! This is at bat #2"
print "Choose a number between 1 and 4."
pitch_guess = int(raw_input("> "))
ball = random.randint(1, 4)
decider = random.randint(1, 10)
if pitch_guess == ball and decider == 10:
print "You hit a homerun!"
score += 5
print "Your score is: ", score
count_2[:] = [0, 0]
elif pitch_guess == ball and 10 > decider >= 9:
print "You hit a triple!"
score += 3
print "Your score is: ", score
count_2[:] = [0, 0]
elif pitch_guess == ball and 8 > decider >= 6:
print "You hit a double!"
score += 2
print "Your score is: ", score
count_2[:] = [0, 0]
elif pitch_guess == ball and 6 > decider >= 4:
print "You hit a single!"
score += 1
print "Your score is: ", score
count_2[:] = [0, 0]
elif pitch_guess == ball and 4 > decider >= 2:
print "That's a ball."
count_2[0] += 1
print "The count is: ", count_2
if count_2[0] == 4:
print "That's a walk. Take your base."
score += 1
print "Your score is: ", score
count_2[:] = [0, 0]
else:
print "That's a strike!"
count_2[1] += 1
print "The count is: ", count_2
if count_2[1] == 3:
print "That's strike 3, you're out!"
outs +=1
print "\n You now have %d outs: " % outs
break
else:
continue
count_3 = [0, 0]
while True:
print "\n"
print "Get ready for the pitch! You have one out left."
print "Choose a number between 1 and 4."
pitch_guess = int(raw_input("> "))
ball = random.randint(1, 4)
decider = random.randint(1, 10)
if pitch_guess == ball and decider == 10:
print "You hit a homerun %s!" % name
score += 5
print "Your score is: ", score
count_3[:] = [0, 0]
elif pitch_guess == ball and 10 > decider >= 8:
print "You hit a triple!"
score += 3
print "Your score is: ", score
count_3[:] = [0, 0]
elif pitch_guess == ball and 8 > decider >= 7:
print "You hit a double!"
score += 2
print "Your score is: ", score
count_3[:] = [0, 0]
elif pitch_guess == ball and 7 > decider >= 5:
print "You hit a single!"
score += 1
print "Your score is: ", score
count_3[:] = [0, 0]
elif pitch_guess == ball and 5 > decider >= 1:
print "That's a ball."
count_3[0] += 1
print "The count is: ", count_1
if count_3[0] == 4:
print "That's a walk. Take your base."
score += 1
print "Your score is: ", score
count_3[:] = [0, 0]
else:
print "That's a strike!"
count_3[1] += 1
print "The count is: ", count_3
if count_3[1] == 3:
print "That's strike 3, you're out!"
outs +=1
print "\n You now have %d outs: " % outs
print "\n Your final score is: ", score
print "\n"
break
else:
continue
def pitchers_mound():
pitches = [
'1 = fastball',
'2 = curveball',
'3 = slider',
'4 = changeup',
]
print '\n Here are your pitches: \n'
print '%s' % ', '.join(map(str, pitches))
print ''
score = 0
game_over = list()
outs = True
while True:
count = [0, 0]
while True:
if count[1] == 3:
print "Strike 3, you struck him out!"
print ""
score += 1
game_over.append(1)
print "Your score is: ", score
outs = False
break
if count[0] == 4:
print "You walked him."
print ""
score -= 1
print "Your score is: ", score
break
print ""
print "Pick your pitch.\n"
print ""
print pitches
pitch_type = int(raw_input("You chose pitch > "))
pitch = random.randint(1, 10)
if pitch_type == 1:
print "%s!" % pitches[0]
if 6 >= pitch >= 3:
print "That's a strike!"
count[1] += 1
print "The count is: ", count
else:
print "That's a ball.\n"
count[0] += 1
print "The count is: ", count
elif pitch_type == 2:
print "%s!\n" % pitches[1]
if 4 >= pitch >= 1:
print "That's a strike!"
count[1] += 1
print "The count is: ", count
else:
print "That's a ball.\n"
count[0] += 1
print "The count is: ", count
elif pitch_type == 3:
print "%s!\n" % pitches[2]
if 2 >= pitch >= 1 or 10 >= pitch >= 9:
print "That's a strike!"
count[1] += 1
print "The count is: ", count
else:
print "That's a ball.\n"
count[0] += 1
print "The count is: ", count
elif pitch_type == 4:
print "%s!\n" % pitches[3]
if 4 >= pitch >= 3 or 9 >= pitch >= 7:
print "That's a strike!"
count[1] += 1
print "The count is: ", count
else:
print "That's a ball.\n"
count[0] += 1
print "The count is: ", count
else:
break
if len(game_over) == 3:
print "\nWay to get out of the inning %s!" % name
print "Your final score was: ", score
print ""
outs = False
break
else:
continue
play_ball()
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.