skip to Main Content

I recently started learning python, and I’ve been having a lot of fun.

I wrote the below program, which runs perfectly in IDLE and Pycharm, but crashes when I try to open the file from Explorer. It does the same on the computers of friend’s I’ve sent it to. Both me and my friends are on Windows 10.

# This program generates networking technobabble, useful for sounding smart and impressing idiots
# This was made to get a working idea of how to use dictionaries.
# It could easily be made more efficient but doo doo gamer brain no code good

import random

print('Welcome to the Networking Technobabble Generator.')
print('This program generates fake acronyms for imaginary protocols')

# Setting out all the possible words.
# Some repeat across the two dictionaries because there weren't multiple possibilities

dic1 = {'a': 'Address', 'b': 'Bridge', 'c': 'Cloud', 'd': 'Data', 'e': 'Exterior', 'f': 'Forwarding', 'g': 'Gateway',
        'h': 'Host', 'i': 'Interior', 'k': 'Kernel', 'l': 'Local', 'm': 'Media', 'n': 'Network',
        'o': 'Open', 'p': 'Port', 'r': 'Routing', 's': 'Service', 't': 'Trunked', 'u': 'User',
        'v': 'Virtual', 'w': 'Weighted', 'x': 'Xpress', 'st': 'Spanning-Tree', 'ai': 'Artificial Intelligence',
        'lb': 'Load Balancing', 'pp': 'Point-to-Point'}

dic2 = {'a': 'Application', 'b': 'Basic', 'c': 'Class-based', 'd': 'Decentralized', 'e': 'Enhanced', 'f': 'Fail-safe',
        'g': 'Generic', 'h': 'Hop', 'i': 'Integrated', 'k': 'Key', 'l': 'Logical', 'm': 'Multipoint', 'n': 'Nonbroadcast',
        'o': 'Overload', 'p': 'Primary', 'r': 'Routing', 's': 'Service', 't': 'Trunked', 'u': 'User',
        'v': 'Virtual', 'w': 'Weighted', 'x': 'Xpress', 'st': 'Spanning-Tree', 'ai': 'Artificial Intelligence',
        'lb': 'Load Balancing', 'pp': 'Point-to-Point'}

# Everything is written out instead of imported because J, Q, X, Y, and Z don't work well, so we exclude them
# It being a little janky allows new letters to be added easily!
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w',
           'st', 'ai', 'lb', 'pp']

# Generating the letters of our acronym
l1 = random.choice(letters)
l2 = random.choice(letters)

# Ensuring you don't get the same letter for l1 and l2
while l1 == l2:
    l2 = random.choice(letters)
    continue

# Choosing l3, then doing same check as above
l3 = random.choice(letters)
while l3 == l1 or l3 == l2:
    l3 = random.choice(letters)
    continue

# Getting the words from the dictionary. The 'if' statement is to choose which dictionary to use.
# Random-ness is weighted toward the first list since it's the more common terms
whichdic = random.randint(1, 3)
if whichdic == 1 or whichdic == 2:
    word1 = dic1.get(str(l1), 0)
else:
    word1 = dic2.get(str(l1), 0)

whichdic = random.randint(1, 3)
if whichdic == 1 or whichdic == 2:
    word2 = dic1.get(str(l2), 0)
else:
    word2 = dic2.get(str(l2), 0)

whichdic = random.randint(1, 3)
if whichdic == 1 or whichdic == 2:
    word3 = dic1.get(str(l3), 0)
else:
    word3 = dic2.get(str(l3), 0)

# Making the letters uppercase. This would have been avoidable if I had planned ahead
l1 = l1.upper()
l2 = l2.upper()
l3 = l3.upper()

# Printing! :)
print('Your acronym is ' + str(l1) + str(l2) + str(l3) + ', which stands for ' + str(word1) + ' ' + str(word2) + ' '
      + str(word3) + '!')

I’ve tried reinstalling Python. Even if I copy the code to another document and delete everything but the print statements, it still crashes for whatever reason. My other programs I’ve made still run fine being opened the same way and running in the terminal.

I’m completely at a loss guys. Any ideas?

2

Answers


  1. Your program isn’t crashing. Because of the way you are opening it by clicking an icon in Explorer, it finishes successfully but closes before you have time to see the output. Put something like

    input("Press enter to close")
    

    at the bottom of the file. The input() will keep the window open long enough for you to see the output.

    Login or Signup to reply.
  2. Your program didn’t crash, it just terminated before you get a chance to read it. You can add a delay time like so:

    from time import sleep
    seconds = 10
    sleep(seconds)
    

    Or you can add an input statement so the user can chooses when to end it 😉

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search