שאלה בפייתון - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

שאלה בפייתון


שמעון נגר
 Share

Recommended Posts

 

שלום לכולם אני מקבל הודעת שגיאה                         TypeError: 'int' object is not callable         כשאני מנסה לטעון את הקוד הזה

def welcome(name):

print ('Hello' ,(name) ,'and welcome to the World of Games (WoG).\nHere you can find many cool games to play.')

 

def load_game():

print ('1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back\n2. Guess Game - guess a number and see if you chose like the computer\n3. Currency Roulette - try and guess the value of a random amount of USD in ILS Gets an input from the user about the game he chose.')

game = int(input('Please choose a game to play: '))

if game > 0 and game < 4:

print ('You have selected ' ,game)

difficulty()

else:

print ('Please enter a number from 1 to 3')

load_game()

 

def difficulty():

difficulty = int(input('Please choose game difficulty from 1 to 5: '))

if difficulty > 0 and difficulty < 6:

print ('You have selected ' ,difficulty)

else:

print ('Please enter a number from 1 to 5')

difficulty()

 

welcome("Guy")

(load_game())

 

 

 

אני מקבל את הודעת השגיאה כשזה נכנס לפונקציה    def difficulty(): והתשובה חורגת מ5

כמה שאני מנסה אני לא מבין למה

אם מישהו יכול לעזור אני מאוד ישמח

קישור לתוכן
שתף באתרים אחרים

לדעתי יש לך פונקציה ומשתנה שנקראים difficulty, שאתה קורא למשתנה מסוג int עם סוגרים () זו השגיאה שתקבל.

אבל להבא תשתמש בתג לקוד <>, פיתון משתמשת בהזחות וזה לא קריא ללא.

 def welcome(name):

print ('Hello' ,(name) ,'and welcome to the World of Games (WoG).\nHere you can find many cool games to play.')
 

def load_game():

print ('1. Memory Game - a sequence of numbers will appear for 1 second and you have to guess it back\n2. Guess Game - guess a number and see if you chose like the computer\n3. Currency Roulette - try and guess the value of a random amount of USD in ILS Gets an input from the user about the game he chose.')

game = int(input('Please choose a game to play: '))

if game > 0 and game < 4:

print ('You have selected ' ,game)

difficulty()

else:

print ('Please enter a number from 1 to 3')

load_game()

 

def difficulty():

difficulty = int(input('Please choose game difficulty from 1 to 5: '))

if difficulty > 0 and difficulty < 6:

print ('You have selected ' ,difficulty)

else:

print ('Please enter a number from 1 to 5')

difficulty()
 

welcome("Guy")

(load_game()) 

 

קישור לתוכן
שתף באתרים אחרים

קודם כל ממש תודה רבה על התשובה

אכן כששיניתי את שם המשתנה הבעיה הסתדרה

וכמובן שאני משתמש בהזחות

 

אבל יש לי 2 שאלות

1. 

ציטוט של Sheik Yerbouti

שאתה קורא למשתנה מסוג int עם סוגרים () זו השגיאה שתקבל

האם כשאני כותב עם סוגריים זה לא מתייחס רק לפונקציה?

2.

ציטוט של Sheik Yerbouti

אבל להבא תשתמש בתג לקוד <>

מה הכוונה בתגים, בפייתון אני לא משתמש בסימונים אלו <>

 

 

קישור לתוכן
שתף באתרים אחרים

הכוונה שיש בסרגל הכלים בפורום כפתור <> .

שים את הקוד שאתה שואל עליו בתוכו, מכיוון שזה שומר על הזחות.

פייתון ללא הזחות קשה להבין,

לדוגמה, האם אתה קורא למשתנה מתוך הפונקציה או אחרי שהיא מסתיימת.

לכן כדאי גם לסיים פונקציה שאינה מחזירה ערך, ללא return, ב- pass.

https://docs.python.org/3/reference/simple_stmts.html#the-pass-statement

נערך על-ידי Sheik Yerbouti
קישור לתוכן
שתף באתרים אחרים

הצטרפ/י לדיון

בשלב זה תוכל/י להצטרף לדיון, ולאחר מכן להצטרף לקהילה שלנו. אם כבר יש לך חשבון אצלנו, אנא התחבר/י עכשיו על מנת להגיב תחת שם המשתמש שלך.
לתשומת לבך: התגובה תופיע לגולשים לאחר אישור של צוות הנהלת הפורומים.

אורח
הוסף תגובה

×   התוכן שהודבק הוא עם עיצוב.   הסר עיצוב

  Only 75 emoji are allowed.

×   הקישור שלך הוטמע אוטומטית.   הצג כקישור רגיל

×   התוכן הקודם שלך שוחזר אוטומטית.   נקה הכל

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
  • צור חדש...