Simplify Python Code

print_with_tab / print_with_whitespace is trivial with Python
string formatting and was mostly used in only 2 lines.
This commit is contained in:
Martin Thoma
2022-04-02 07:32:09 +02:00
parent 354c1f9ab3
commit c500424956
47 changed files with 208 additions and 387 deletions

18
96_Word/python/word.py Normal file → Executable file
View File

@@ -1,7 +1,10 @@
#!/usr/bin/env python3
# WORD
#
# Converted from BASIC to Python by Trevor Hobson
"""
WORD
Converted from BASIC to Python by Trevor Hobson
"""
import random
@@ -21,7 +24,7 @@ words = [
]
def play_game():
def play_game() -> None:
"""Play one round of the game"""
random.shuffle(words)
@@ -54,16 +57,15 @@ def play_game():
if i == j:
guess_progress[j] = guess_word[i]
print(
"There were",
matches,
"matches and the common letters were... " + common_letters,
f"There were {matches}",
f"matches and the common letters were... {common_letters}",
)
print(
"From the exact letter matches, you know............ "
+ "".join(guess_progress)
)
if "".join(guess_progress) == guess_word:
print("\nYou have guessed the word. It took", guess_count, "guesses!")
print(f"\nYou have guessed the word. It took {guess_count} guesses!")
break
elif matches == 0:
print("\nIf you give up, type '?' for you next guess.")