mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 15:16:33 -08:00
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:
@@ -7,14 +7,6 @@ Ported by Dave LeCompte
|
||||
"""
|
||||
|
||||
|
||||
def print_with_tab(space_count: int, msg: str) -> None:
|
||||
if space_count > 0:
|
||||
spaces = " " * space_count
|
||||
else:
|
||||
spaces = ""
|
||||
print(spaces + msg)
|
||||
|
||||
|
||||
def is_yes_ish(answer: str) -> bool:
|
||||
cleaned = answer.strip().upper()
|
||||
if cleaned in ["Y", "YES"]:
|
||||
@@ -23,29 +15,21 @@ def is_yes_ish(answer: str) -> bool:
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print_with_tab(34, "NAME")
|
||||
print_with_tab(15, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
print(" " * 34 + "NAME")
|
||||
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n")
|
||||
print("HELLO.")
|
||||
print("MY NAME iS CREATIVE COMPUTER.")
|
||||
name = input("WHAT'S YOUR NAME (FIRST AND LAST)?")
|
||||
print()
|
||||
name_as_list = list(name)
|
||||
reversed_name = "".join(name_as_list[::-1])
|
||||
print(f"THANK YOU, {reversed_name}.")
|
||||
print()
|
||||
print(f"THANK YOU, {reversed_name}.\n")
|
||||
print("OOPS! I GUESS I GOT IT BACKWARDS. A SMART")
|
||||
print("COMPUTER LIKE ME SHOULDN'T MAKE A MISTAKE LIKE THAT!")
|
||||
print()
|
||||
print()
|
||||
print("COMPUTER LIKE ME SHOULDN'T MAKE A MISTAKE LIKE THAT!\n\n")
|
||||
print("BUT I JUST NOTICED YOUR LETTERS ARE OUT OF ORDER.")
|
||||
|
||||
sorted_name = "".join(sorted(name_as_list))
|
||||
print(f"LET'S PUT THEM IN ORDER LIKE THIS: {sorted_name}")
|
||||
print()
|
||||
print()
|
||||
print(f"LET'S PUT THEM IN ORDER LIKE THIS: {sorted_name}\n\n")
|
||||
|
||||
print("DON'T YOU LIKE THAT BETTER?")
|
||||
like_answer = input()
|
||||
|
||||
Reference in New Issue
Block a user