-
-
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.
- Loading branch information
1 parent
89097f3
commit beb5275
Showing
2 changed files
with
38 additions
and
51 deletions.
There are no files selected for viewing
52 changes: 20 additions & 32 deletions
52
docs/books/computer-games/computer-battle-games/the_vital_message/the_vital_message.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,50 +1,38 @@ | ||
# Import 'random' so we can generate random numbers. | ||
# The 'string' module gives us access to string-related utilities | ||
# The 'time' module helps us to wait for some time | ||
|
||
|
||
import random | ||
import string | ||
import time | ||
print("VITAL MESSAGE") | ||
|
||
print('VITAL MESSAGE') | ||
|
||
# Variable to store the difficulty i.e length of string | ||
level_difficulty = 0 | ||
difficulty = 0 | ||
|
||
# Loop until the right difficulty level is enterred | ||
while level_difficulty < 4 or level_difficulty > 10: | ||
print("HOW DIFFICULT? (4-10)") | ||
while difficulty < 4 or difficulty > 10: | ||
print('How difficult do you want the game to be? (4-10)') | ||
x = int(input()) | ||
level_difficulty = x | ||
|
||
# Function to clear the screen | ||
# This simply clears the screen by printing 64 blank lines | ||
|
||
|
||
def clrsc(): | ||
print('\n' * 64) | ||
|
||
|
||
# Variable to store the secret message | ||
message = "" | ||
difficulty = x | ||
|
||
for i in range(0, level_difficulty): | ||
message += (random.choice(string.ascii_letters)) | ||
# Create the secret message | ||
message = ''.join( | ||
random.choice(string.ascii_letters) | ||
for i in range(0, difficulty) | ||
) | ||
|
||
print("SEND THIS MESSAGE:") | ||
print('Send this message:') | ||
print(message) | ||
|
||
# Displaying the secret message in accordance of the difficulty level | ||
time.sleep(0.5 * level_difficulty) | ||
clrsc() | ||
# Display the secret message in accordance with the difficulty level | ||
time.sleep(0.5 * difficulty) | ||
|
||
print("Enter the secret code that need to be transferred") | ||
code = input() | ||
code = input('Enter the secret code that need to be transferred') | ||
|
||
if(code == message): | ||
print("MESSAGE CORRECT") | ||
print("THE WAR IS OVER") | ||
if code == message: | ||
print('MESSAGE CORRECT') | ||
print('The war is over!') | ||
else: | ||
print("YOU GOT IT WRONG") | ||
print("YOU SHOULD HAVE SENT:") | ||
print(message) | ||
print('YOU GOT IT WRONG') | ||
print('You should have sent:', message) |
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