Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error message with module
#1
Hello,

I am trying to make a dice game. I came across an error and I cannot figure out what is happening. Could someone explain this error? Everything in the dice game is working except this part. Here is the code.

from die import Die
Error:
ModuleNotFoundError: No module named 'die'
Reply
#2
die most be your filename die.py,an Die is a class or function.
Example:
# die.py
import random

def dice_toss():
    return random.randint(1, 6)
Use:
λ ptpython
>>> from die import dice_toss

>>> dice_toss()
4
>>> dice_toss()
4
>>> dice_toss()
6 
>>> dice_toss()
2
Reply
#3
Thank you so much for helping me. I have a new error now. My program shows me that their is an error with this line. Also, I am trying to implement two players, one of which is the computer. Is this the correct way of doing this? I will also post the code after the error.

if val == 'unrolled': val = -1
			if (val >= 1 and val <= self.sides) or val == -1:
				self._value = va
player1 = player1dice player2 = player2dice
Error:
else: SyntaxError: invalid syntax
Reply
#4
if val == 'unrolled': val = -1 # no code after the :
there shouldn't be any code after the :
val = -1 should be moved to the next line
Use 4 spaces for indents.
if val == 'unrolled':
    val = -1
    if (val >= 1 and val <= self.sides) or val == -1:
        self._value = va # should this be va or val?
player1 = player1dice player2 = player2dice
Do these assignments on separate lines
player1 = player1dice
player2 = player2dice
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 1,006 Aug-17-2023, 07:53 PM
Last Post: Visiting
  Another Error message. the_jl_zone 2 974 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,988 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  understanding error message krlosbatist 1 1,904 Oct-24-2021, 08:34 PM
Last Post: Gribouillis
  Error message pybits 1 39,952 May-29-2021, 10:26 AM
Last Post: snippsat
  f-string error message not understood Skaperen 4 3,328 Mar-16-2021, 07:59 PM
Last Post: Skaperen
  Overwhelmed with error message using pandas drop() EmmaRaponi 1 2,357 Feb-18-2021, 07:31 PM
Last Post: buran
  Winning/Losing Message Error in Text based Game kdr87 2 2,987 Dec-14-2020, 12:25 AM
Last Post: bowlofred
  Don't understand error message Milfredo 2 2,047 Aug-24-2020, 05:00 PM
Last Post: Milfredo
  what to do about this error message deric23 0 1,912 May-15-2020, 02:49 PM
Last Post: deric23

Forum Jump:

User Panel Messages

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