程序在Pycharm和IDLE中运行,但直接打开时会崩溃

问题描述 投票:0回答:1

我最近开始学习python,并且一直很有趣。

我编写了以下程序,该程序可以在IDLE和Pycharm中完美运行,但是当我尝试从资源管理器中打开文件时崩溃。在我发送给朋友的计算机上,它的功能相同。我和我的朋友都在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) + '!')

我尝试重新安装Python。即使我将代码复制到另一个文档并删除除打印语句以外的所有内容,由于任何原因它仍然会崩溃。我编写的其他程序仍然可以以相同的方式运行并在终端中运行。

我完全不知所措。有什么想法吗?

python random pycharm
1个回答
0
投票
input("Press enter to close")

位于文件底部。

© www.soinside.com 2019 - 2024. All rights reserved.