Итак, мне нужно импортировать множество пользовательских модулей в мой .py-файл. Если бы я мог хранить их в одном каталоге, было бы намного проще найти основную программу.
Я специально делаю библейскую викторину, поэтому мне нужны все эти модули. Каждый модуль содержит вопросы, например, в Бытии 50, в Исходе 40, в Левите 27 и т. д. Это первая книга, которую я еще не закончил:
# Genesis.py
import random
def int_errorcheck(num):
try:
num = int(num)
return num
except:
print("You must enter an integer value!")
def check_if_right(choice):
global mychoice
global score
mychoice = input()
mychoice = int_errorcheck(mychoice)
if mychoice == choice:
print("Correct!")
score += 1
else:
print("The answer was", choice)
def question(value):
global score
if value == 1:
print('On which day of creation were amphibians created?')
print('1. Day 5')
print('2. Day 6')
print('3. Day 7')
print('4. Natrual selection')
check_if_right(2)
elif value == 2:
print("Which of these statements is true?")
print("1. The Pishon river flows through the land of Cush.")
print("2. The Tigris river flows west of Assyria.")
print("3. The Gihon river flows through the land of Cush.")
print("4. The fourth river is named the Havailah.")
check_if_right(3)
elif value == 3:
print("Why did Eve eat the forbidden fruit?")
print("1. She wanted to become like God")
print("2. The serpent deceived her")
print("3. It looked good")
print("4. All of the above")
check_if_right(3)
elif value == 4:
print("Which of these statements are true:")
print("1. Abel was older, took care of sheep")
print("2. Abel was younger, took care of crops/plants")
print("3. Cain was younger, took care of sheep")
print("4. Cain was older, took care of crops/plants")
check_if_right(4)
elif value == 5:
print("When did Noah have Shem, Ham, and Japheth?")
print("1. 500 years")
print("2. 520 years")
print("3. 540 years")
print("4. 560 years")
check_if_right(1)
elif value == 6:
print("What material was the ark made of?")
print("1. Oak wood")
print("2. Gopher wood")
print("3. Birch wood")
print("4. Spruce wood")
check_if_right(2)
elif value == 7:
print("What word did God use for Noah's family entering the Ark?")
print("1. 'You and all your household'")
print("2. 'You and all your group'")
print("3. 'You and all your family'")
print("4. 'You and all your kids'")
check_if_right(1)
elif value == 8:
print("How long did the ark stay on the water?")
print("1. 40 days")
print("2. 150 days")
print("3. 187 days")
print("4. 370 days")
check_if_right(4)
elif value == 9:
print("What does the rainbow represent?")
print("1. A promise")
print("2. LGBTQ+")
print("3. Something beautiful")
print("4. It dosen't represent anything")
check_if_right(1)
elif value == 10:
print("Which child of Noah had the most sons?")
print("1. Ham")
print("2. Japheth")
print("3. Shem")
print("4. They all had the same number")
check_if_right(2)
else:
score += 1
def main():
input("Ready to begin?")
global score
score = 0
print('Bible Quiz')
print('----------')
for i in range(0, 50):
question(random.randrange(1, 51))
print(f"Your score was {score} out of {i + 1}.")
Моя цель — отделить пользовательские модули от основной программы, чтобы основную программу было намного легче найти, но когда я пытаюсь это сделать, я получаю ошибку ModuleNotFoundError:
import genesis
genesis.question(random.randrange(1, 11))
А также: чтобы очистить все библиотеки, как мне импортировать все 66 моих пользовательских модулей, чтобы код не выглядел так:
import genesis
import exodus
import leviticus
import numbers
import deuteronomy
import joshua
import judges
# etc...
Подробнее здесь: https://stackoverflow.com/questions/798 ... ry-without
Как отделить пользовательские модули от моей основной программы в подкаталог, не получая сообщения «Ошибка «Модуль не на ⇐ Python
Программы на Python
1767978158
Anonymous
Итак, мне нужно импортировать множество пользовательских модулей в мой .py-файл. Если бы я мог хранить их в одном каталоге, было бы намного проще найти основную программу.
Я специально делаю библейскую викторину, поэтому мне нужны все эти модули. Каждый модуль содержит вопросы, например, в Бытии 50, в Исходе 40, в Левите 27 и т. д. Это первая книга, которую я еще не закончил:
# Genesis.py
import random
def int_errorcheck(num):
try:
num = int(num)
return num
except:
print("You must enter an integer value!")
def check_if_right(choice):
global mychoice
global score
mychoice = input()
mychoice = int_errorcheck(mychoice)
if mychoice == choice:
print("Correct!")
score += 1
else:
print("The answer was", choice)
def question(value):
global score
if value == 1:
print('On which day of creation were amphibians created?')
print('1. Day 5')
print('2. Day 6')
print('3. Day 7')
print('4. Natrual selection')
check_if_right(2)
elif value == 2:
print("Which of these statements is true?")
print("1. The Pishon river flows through the land of Cush.")
print("2. The Tigris river flows west of Assyria.")
print("3. The Gihon river flows through the land of Cush.")
print("4. The fourth river is named the Havailah.")
check_if_right(3)
elif value == 3:
print("Why did Eve eat the forbidden fruit?")
print("1. She wanted to become like God")
print("2. The serpent deceived her")
print("3. It looked good")
print("4. All of the above")
check_if_right(3)
elif value == 4:
print("Which of these statements are true:")
print("1. Abel was older, took care of sheep")
print("2. Abel was younger, took care of crops/plants")
print("3. Cain was younger, took care of sheep")
print("4. Cain was older, took care of crops/plants")
check_if_right(4)
elif value == 5:
print("When did Noah have Shem, Ham, and Japheth?")
print("1. 500 years")
print("2. 520 years")
print("3. 540 years")
print("4. 560 years")
check_if_right(1)
elif value == 6:
print("What material was the ark made of?")
print("1. Oak wood")
print("2. Gopher wood")
print("3. Birch wood")
print("4. Spruce wood")
check_if_right(2)
elif value == 7:
print("What word did God use for Noah's family entering the Ark?")
print("1. 'You and all your household'")
print("2. 'You and all your group'")
print("3. 'You and all your family'")
print("4. 'You and all your kids'")
check_if_right(1)
elif value == 8:
print("How long did the ark stay on the water?")
print("1. 40 days")
print("2. 150 days")
print("3. 187 days")
print("4. 370 days")
check_if_right(4)
elif value == 9:
print("What does the rainbow represent?")
print("1. A promise")
print("2. LGBTQ+")
print("3. Something beautiful")
print("4. It dosen't represent anything")
check_if_right(1)
elif value == 10:
print("Which child of Noah had the most sons?")
print("1. Ham")
print("2. Japheth")
print("3. Shem")
print("4. They all had the same number")
check_if_right(2)
else:
score += 1
def main():
input("Ready to begin?")
global score
score = 0
print('Bible Quiz')
print('----------')
for i in range(0, 50):
question(random.randrange(1, 51))
print(f"Your score was {score} out of {i + 1}.")
Моя цель — отделить пользовательские модули от основной программы, чтобы основную программу было намного легче найти, но когда я пытаюсь это сделать, я получаю ошибку ModuleNotFoundError:
import genesis
genesis.question(random.randrange(1, 11))
А также: чтобы очистить все библиотеки, как мне импортировать все 66 моих пользовательских модулей, чтобы код не выглядел так:
import genesis
import exodus
import leviticus
import numbers
import deuteronomy
import joshua
import judges
# etc...
Подробнее здесь: [url]https://stackoverflow.com/questions/79864349/how-to-separate-custom-modules-from-my-main-program-into-a-subdirectory-without[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия