-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rosalindfdt/master
first program in computer battlegames
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
docs/books/computer-games/computer-battle-games/robot_missile/robot_missile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
import random | ||
import string | ||
|
||
print('ROBOT MISSILE') | ||
print() | ||
print('Type the correct code letter (A-Z) to defuse the missile.') | ||
print('You have 4 chances.') | ||
print() | ||
|
||
code = random.choice(string.ascii_lowercase) | ||
|
||
guesses = 0 | ||
success = False | ||
|
||
while not success and guesses < 4: | ||
guess = input('What is your guess? ') | ||
guesses += 1 | ||
|
||
if guess.lower() == code: | ||
success = True | ||
if guess < code: | ||
print('The code is later than %s in the alphabet' % guess) | ||
if guess > code: | ||
print('The code is earlier than %s in the alphabet' % guess) | ||
|
||
if success: | ||
print('TICK... FIZZ... CLICK...' | ||
'\nYou did it!') | ||
else: | ||
print('BOOOOOOOOMMM...' | ||
'\nYou blew it!' | ||
'\nThe correct code was \'%s\'.' % code) |