Python: Make code testable

Avoid executing code on module level as this prevents importing the
module for testing. Especially infinite loops are evil.
This commit is contained in:
Martin Thoma
2022-03-19 09:54:52 +01:00
parent f40a1fc465
commit 8495e59a8f
23 changed files with 1049 additions and 973 deletions

View File

@@ -126,27 +126,31 @@ def final_message(profits):
print("Collect your winings from the H&M cashier.")
profits = 0
keep_betting = True
def main():
profits = 0
keep_betting = True
initial_message()
while keep_betting:
m = input_betting()
w = spin_wheels()
profits = adjust_profits(w, m, profits)
initial_message()
while keep_betting:
m = input_betting()
w = spin_wheels()
profits = adjust_profits(w, m, profits)
print(f"Your standings are ${profits}")
answer = input("Again?")
print(f"Your standings are ${profits}")
answer = input("Again?")
try:
if not answer[0].lower() == "y":
try:
if not answer[0].lower() == "y":
keep_betting = False
except IndexError:
keep_betting = False
except IndexError:
keep_betting = False
final_message(profits)
final_message(profits)
if __name__ == "__main__":
main()
######################################################################
#
# Porting notes