ich bin der neue. Habe mich dazu entschlossen Python lernen zu wollen. Ich arbeite einen kostenlosen online Kurs zu diesem Thema ab. Bisher bin ich auch gut durch gekommen. Nun bin ich bei dem Kapitel Random angekommen. Obwohl ich mich an die Bsp. halte, will es bei mir leider nicht funktionieren.
Deswegen habe ich mich dazu entschieden hier nach Hilfe zu fragen.
Hier ist mal mein Code:
Code: Alles auswählen
import random
def zufallszahl():
return random.random() * 9 + 1
print (zufallszahl())
Code: Alles auswählen
python3 random.py
Traceback (most recent call last):
File "random.py", line 3, in <module>
import random
File "/home/mein-name/scripts/python-übungen/onlinekurs/random.py", line 7, in <module>
print (zufallszahl())
File "/home/mein-name/scripts/python-übungen/onlinekurs/random.py", line 6, in zufallszahl
return random.random() * 9 + 1
TypeError: 'module' object is not callable
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module>
import subprocess, tempfile, os.path, re, pwd, grp, os, time, io
File "/usr/lib/python3.8/tempfile.py", line 184, in <module>
from random import Random as _Random
File "/home/mein-name/scripts/python-übungen/onlinekurs/random.py", line 7, in <module>
print (zufallszahl())
File "/home/mein-name/scripts/python-übungen/onlinekurs/random.py", line 6, in zufallszahl
return random.random() * 9 + 1
TypeError: 'module' object is not callable
Original exception was:
Traceback (most recent call last):
File "random.py", line 3, in <module>
import random
File "/home/mein-name/scripts/python-übungen/onlinekurs/random.py", line 7, in <module>
print (zufallszahl())
File "/home/mein-name/scripts/python-übungen/onlinekurs/random.py", line 6, in zufallszahl
return random.random() * 9 + 1
TypeError: 'module' object is not callable
Als Editor verwende ich VSCode.
Hoffe Ihr könnt mir bei meinem Problem helfen.
Ich danke Euch.
MfG
Fimbur