dimanche 1 avril 2018

Python 3.x runs in IDLE but has issues in Pycharm

I'm new to the forum and Python. I've been teaching myself Python 3 for the last couple of weeks using IDLE to create my code which has been working great. I recently decided to download and install the community version of PyCharm. Here's my issue...when I opened my last Python project, which worked fine in IDLE, into PyCharm and tried to run it, it gave me back two errors. I've been using the "import random" and "random.randint()" command to generate numbers. When I use the "Debug" command in PyCharm, the program runs fine but when I use the "Run" function it gives me two errors. Here's my code:

import random

# Megamillion Generator
def mega():
    s = []
    a = random.randint(start, finish)
    b = random.randint(start, finish)
    c = random.randint(start, finish)
    d = random.randint(start, finish)
    e = random.randint(start, finish)
    s.append(a)
    s.append(b)
    s.append(c)
    s.append(d)
    s.append(e)
    s.sort()
    if x < 10:
        print("Random ", str(i), " ", end="")
        print(s)
        print("Sorted ", end="")
        print(end="  ")
        print(s)
    else:
        print("Random", str(i), end="")
        print(s)
        s.sort()
        print("Sorted ", end="")
        print(end="")
        print(s)
    return s

    # 3 digit Generator


def digit_3():
    s = []
    a = random.randint(0, 9)
    b = random.randint(0, 9)
    c = random.randint(0, 9)
    s.append(a)
    s.append(b)
    s.append(c)
    print(format, "Random {0:2}")
    print((i), end="")
    print(s)
    s.sort()
    print("Sorted", end="")
    print(end="  ")
    print(s)
    return s

    # 4 digit Generator


def digit_4():
    s = []
    a = random.randint(0, 9)
    b = random.randint(0, 9)
    c = random.randint(0, 9)
    d = random.randint(0, 9)
    s.append(a)
    s.append(b)
    s.append(c)
    s.append(d)
    print("Random ", end="")
    print((i), end="")
    print(s)
    s.sort()
    print("Sorted", end="")
    print(end="  ")
    print(s)
    return s

    # Begin Generator


gentype = str(input("Enter '3' for 3-digit, '4' for 4-digit, 'm' for Megamillion or 'all' for all three"))

x = int(input("Enter a number "))
x = x + 1
if gentype == '3':
    for i in range(1, x):
        digit_3()
elif gentype == '4':
    for i in range(1, x):
        digit_4()
else:
    start = int(input("Enter smallest number to generate "))
    finish = int(input("Enter highest number to generate "))
    for i in range(1, x):
        mega()

And here's the error msg: line 1, in import random line 5, in a=random.randint(1,70) AttributeError: module 'random' has no attribute 'randint'

Any Help would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire