#python programing task #this is were the definitions of my code are #ask user would you like a game and does somthing according to there answer #------------------------------------------------------------------ def ask_ok (prompt, complaint='Yes or No Please!! ', retries=2): while True: ok = input(prompt) if ok in ['y','Y','Yes','YES','yes']: return False if ok in ['n', 'no', 'N', 'NO','No']: raise SystemExit() retries = retries - 1 if retries < 0: raise IOError('uncooperative user') print(complaint) #------------------------------------------------- def ask_which(prompt, complaint='1 or 2 please!!', retries=2): while True: game_choice= input(prompt) if game_choice in ['1','G1','g1','game1']: Game_1() if game_choice in ['2','Game2','G2','game2']: Game_2() retries = retries - 1 if retries < 0: raise IOError('uncooperative user') print(complaint) #---------------------------------------------- def Game_1(): #this program is a guessing game that uses while #loop to keep count of tries and if loop to check #answers against a list answer_attempt = 5 #number of guesses you get numbers = ['3','5','6','8','9'] #correct answers correct_answer = [] #creates name for all the possible answers while(answer_attempt > 0): #it will run until it hits 0 guess = input('guess a number between 0 and 10.') if guess in numbers: #hypothesis correct_answer.append(guess) print('you guessed a correct number.') #printing else: #other half of hypothesis print('sorry, wrong number.') answer_attempt-=1 #printing sorry and giving you one less try to guess print('you have ' ,answer_attempt,'more guesses.') #tells you what you have left print('Done') #done number_correct= len(correct_answer) print('you guessed',number_correct,'numbers correctly.') print(correct_answer) #game stats again_answer= input('would you like to play another game. yes or no') if again_answer in ['y','Y','Yes','YES','yes']: ask_which('Would you like to play Game1,the number game?, or Game2, rock paper scissors') else: raise SystemExit #---------------------------------------------- def Game_2(): correct_answers = ['rock'] #creates a answer so player can be rock or lose guess = input ('rock, paper, scissors') #asks player rock paper scissors and compares answer to correct answer. #this is what make the opponent/code play if guess in correct_answers: #this is what decides if the the user has won or not print('rock beats scissors, you won') if guess == ('scissors'): print ('we tied') #this tells the player that they have won if guess == ('paper'): print('Scissors beats paper, you lose') #this tells the user they have lost again_answer= input('would you like to play another game. yes or no') if again_answer in ['y','Y','Yes','YES','yes']: ask_which('Would you like to play Game1,the number game?, or Game2, rock paper scissors') else: raise SystemExit #----------------------------------------------- ask_ok('would you like to play a game? y/n') ask_which('Would you like to play Game1,the number game?, or Game2, rock paper scissors')
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