#Jacob Rutter, Assignment 3 --Golf Assignment, Jan 26, 2014 #I have created a program that will ask for the user to input #hole, par, and stroke count. The program will consider the inputs #and print the proper response. import random #I am importing random to allow the program to offer multiple #different output responses for a single input. def main(): print ('Welcome to your golf score simulator.') continue_on = 'y' while continue_on == 'y': #I made it so the user can continue the program #without leaving the shell. hole = int(input('Please enter the hole number.')) while hole <= 0: #I have decided to create an error loop guarding against #inputs less than or equal to 0. Each hole, par, and strokes will have #this same validating loop. print('Error. The hole cannot be less than 1.') hole = int(input('Enter the correct hole.')) print (('Ok, you are on hole'),hole,('. What is the par for hole'),hole,('?')) par = int(input('Enter the par for this hole.')) while par <= 0: print('Error. The par cannot be less than 1.') par = int(input('Enter the correct par for hole.')) print (('So hole'),hole,('is a par'),par,('.')) strokes = int(input('How many strokes did it take you?')) while strokes <=0: print('Error. The stroke count cannot be less than 1.') strokes = int(input('Enter the correct stroke count.')) #Next I will assign various responses to the inputs given above. I am creating multiple #possibilities for each so that the program will vary even when the input is identical. if strokes == par: par1 = 'Good job, on hole',hole,'you went even.' par2 = 'Not too shabby. You parred hole',hole,'.' par3 = 'Well you shot par on hole',hole,'nice work.' par_responses = [par1,par2,par3] #Creating a list for par responses. myNewString = random.choice(par_responses) print(myNewString) elif strokes ==(par-1): birdie1 = 'Great work, on hole',hole,'you shot a birdie.' birdie2 = 'Thats pretty good. You got a birdie on hole',hole,'.' birdie3 = 'On hole',hole,'you shot a birdie. Congrats.' birdie_responses = [birdie1,birdie2,birdie3] myNewString = random.choice(birdie_responses) print (myNewString) elif strokes ==(par-2): eagle1 = 'Wow! You eagled hole',hole,'!' eagle2 = 'That is amazing! You just shot eagle on hole',hole, '!' eagle3 = 'On hole',hole, 'you got an eagle! Thats rad.' eagle_responses = [eagle1,eagle2,eagle3] myNewString = random.choice(eagle_responses) print (myNewString) elif strokes ==(par-3): albatross1 = 'On hole',hole,'you got an albatross!' albatross2 = 'Simply amazing. Chalk up hole',hole,'as an albatross!' albatross3 = 'That was splendid. You shot an albatross on hole',hole albatross_responses = [albatross1,albatross2,albatross3] myNewString = random.choice(albatross_responses) print (myNewString) print('Thats really impressive.') elif strokes ==(par-4): print(('On hole number'),hole,('you shot a condor!')) print('Are you a pro?') elif strokes ==(par-5): print(('Unbelievable! You shot an ostrich on hole'),hole,('!')) elif strokes ==(par+1): print(('Ah, thats too bad. On hole'),hole,('you bogeyed.')) elif strokes ==(par+2): print(('Hole'),hole,('got you this time. You double bogeyed.')) print('That is unfortunate, keep practicing Skipper!') elif strokes ==(par+3): print(('Oh man, hole'),hole,('sure is tough. You shot a triple bogey.')) elif strokes >=(par+4): print(('You shot'),(strokes-par),('over par on hole'),hole,('.')) print('Some friendly advice? Do not quit your day job.') if strokes == (1): print('You got a hole in one! You really have a wonderful swing.') if strokes == (4): print('Four strokes, thats what we call a sailboat out here on the green.') if strokes == (8): print('Hmm, eight strokes. Nice dog balls.') if strokes == (10): print('Woa woa Bo Derek! You can do better.') print("\r\n") continue_on = input('Do you want to enter another hole?' + \ '(Enter y for yes): ') main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question