Python Forum
Python 25 Line Challenge
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 25 Line Challenge
#32
I'm still looking forward to others contributing to the thread. Until that moment, here is another interpretation of an original entry into that contest. A sub hunt game in 24 lines. I think the next version will need graphics.

import random
print("There is a sub in your patrol area, a 10x10x10 grid numbered 0-9\nFlush it out by launching depth chargers. Bullseye the sub and you")
print("will be the hero of the day. Allow the sub to escape and you will\nswabbing the decks for the rest of your career.")
sub = {"x": random.randint(0,9), "y": random.randint(0,9), "depth": random.randint(0,9)}
charges, sunk = 20, False
print("You have",charges,"charges. Good luck!")
print(sub)
while charges > 0 and not sunk:
    chg = {"x": int(input("     x: ")), "y": int(input("     y: ")), "depth": int(input(" depth: "))}
    dist = ((sub["x"]-chg["x"])**2 + (sub["y"]-chg["y"])**2 + (sub["depth"]-chg["depth"])**2)**0.5
    
    if chg == sub:
        print("\nA massive explosion breaks the surface. Debis of the destroyed sub floats above the bubbles.")
        sunk = True
    elif dist <= 4:
        print("\nThe sub was rocked by the charge before slipping away\nBubbles in the water show the sub was at",sub,"\nwas rocked by the charge before slipping away\n")
        sub = {"x": sub["x"] + random.randint(-1,1), "y": sub["y"] + random.randint(-1,1), "depth": sub["depth"] + random.randint(-1,1)}
    else:
        print("The sub silently waits. You have",charges,"charges remaining.\n")
        charges = charges - 1
if sunk == True:
    print("You sunk the sub. Lunch with the president and the metal of hour awaits")
else:
    print("The sub escaped. Your commander hands you a mop and tells you to get started")
    
Reply


Messages In This Thread
Python 25 Line Challenge - by codingCat - May-02-2022, 01:08 PM
RE: Python 25 Line Challenge - by codingCat - May-02-2022, 01:11 PM
RE: Python 25 Line Challenge - by menator01 - May-02-2022, 08:02 PM
RE: Python 25 Line Challenge - by codingCat - May-03-2022, 11:23 AM
RE: Python 25 Line Challenge - by Gribouillis - May-03-2022, 12:24 PM
RE: Python 25 Line Challenge - by codingCat - May-04-2022, 06:52 PM
RE: Python 25 Line Challenge - by menator01 - May-03-2022, 07:49 PM
RE: Python 25 Line Challenge - by codingCat - May-04-2022, 06:55 PM
RE: Python 25 Line Challenge - by Gribouillis - May-03-2022, 09:24 PM
RE: Python 25 Line Challenge - by codingCat - May-04-2022, 07:06 PM
RE: Python 25 Line Challenge - by menator01 - May-05-2022, 07:10 PM
RE: Python 25 Line Challenge - by Coricoco_fr - May-09-2022, 01:11 PM
RE: Python 25 Line Challenge - by codingCat - May-09-2022, 02:27 PM
RE: Python 25 Line Challenge - by menator01 - May-06-2022, 07:33 PM
RE: Python 25 Line Challenge - by codingCat - May-09-2022, 11:49 AM
RE: Python 25 Line Challenge - by codingCat - May-09-2022, 12:17 PM
RE: Python 25 Line Challenge - by menator01 - May-09-2022, 06:04 PM
RE: Python 25 Line Challenge - by codingCat - May-09-2022, 06:33 PM
RE: Python 25 Line Challenge - by menator01 - May-09-2022, 06:36 PM
RE: Python 25 Line Challenge - by Coricoco_fr - May-11-2022, 05:34 PM
RE: Python 25 Line Challenge - by Gribouillis - May-09-2022, 06:30 PM
RE: Python 25 Line Challenge - by menator01 - May-09-2022, 06:33 PM
RE: Python 25 Line Challenge - by Gribouillis - May-09-2022, 06:51 PM
RE: Python 25 Line Challenge - by menator01 - May-09-2022, 07:03 PM
RE: Python 25 Line Challenge - by Gribouillis - May-09-2022, 07:07 PM
RE: Python 25 Line Challenge - by codingCat - May-10-2022, 01:43 PM
RE: Python 25 Line Challenge - by codingCat - May-10-2022, 02:55 PM
RE: Python 25 Line Challenge - by Gribouillis - May-10-2022, 07:03 PM
RE: Python 25 Line Challenge - by Gribouillis - May-11-2022, 05:51 AM
RE: Python 25 Line Challenge - by codingCat - May-11-2022, 11:33 AM
RE: Python 25 Line Challenge - by codingCat - May-12-2022, 07:10 PM
RE: Python 25 Line Challenge - by codingCat - May-13-2022, 07:00 PM
RE: Python 25 Line Challenge - by codingCat - May-17-2022, 01:50 PM
RE: Python 25 Line Challenge - by codingCat - May-17-2022, 06:24 PM
RE: Python 25 Line Challenge - by codingCat - May-18-2022, 07:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python 100 line Challenge codingCat 9 3,270 Jun-20-2022, 07:18 AM
Last Post: Coricoco_fr
  Zen Python Challenge ichabod801 3 4,117 Aug-13-2018, 12:02 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020