פורסם 2020 ביולי 195 שנים שלום לכולם אני מקבל הודעת שגיאה 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 כמה שאני מנסה אני לא מבין למה אם מישהו יכול לעזור אני מאוד ישמח
פורסם 2020 ביולי 195 שנים לדעתי יש לך פונקציה ומשתנה שנקראים 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())
פורסם 2020 ביולי 205 שנים מחבר קודם כל ממש תודה רבה על התשובה אכן כששיניתי את שם המשתנה הבעיה הסתדרה וכמובן שאני משתמש בהזחות אבל יש לי 2 שאלות 1. ציטוט של Sheik Yerbouti שאתה קורא למשתנה מסוג int עם סוגרים () זו השגיאה שתקבל האם כשאני כותב עם סוגריים זה לא מתייחס רק לפונקציה? 2. ציטוט של Sheik Yerbouti אבל להבא תשתמש בתג לקוד <> מה הכוונה בתגים, בפייתון אני לא משתמש בסימונים אלו <>
פורסם 2020 ביולי 205 שנים הכוונה שיש בסרגל הכלים בפורום כפתור <> . שים את הקוד שאתה שואל עליו בתוכו, מכיוון שזה שומר על הזחות. פייתון ללא הזחות קשה להבין, לדוגמה, האם אתה קורא למשתנה מתוך הפונקציה או אחרי שהיא מסתיימת. לכן כדאי גם לסיים פונקציה שאינה מחזירה ערך, ללא return, ב- pass. https://docs.python.org/3/reference/simple_stmts.html#the-pass-statement נערך 2020 ביולי 205 שנים על-ידי Sheik Yerbouti
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.