logo

קווין בפייתון

קווין היא תוכנית שלא לוקחת קלט אלא מפיקה עותק של הקוד שלה. דנו קווין ב-C . The shortest possible quine in python is just a single line of code! Python
_='_=%r;print _%%_';print _%_ 
In case of Python3.x Python
_='_=%r;print (_%%_)';print (_%_) 
הֶסבֵּר: הקוד לעיל הוא שימוש קלאסי בעיצוב מחרוזת. ראשית אנו מגדירים משתנה _ ומקצה לו '_=%r;print _%%_'. שנית אנחנו מדפיסים _%_ . כאן אנו מדפיסים _ עם _ כקלט לעיצוב מחרוזת. כָּך %r ב-_ מקבל את הערך של _. אתה יכול אפילו להשתמש %s בִּמקוֹם %r . השתמשנו כפול % ב-'_=%r;print _%%_' כדי לברוח % . But you may say that the below code is the smallest right! Python
print open(__file__).read() 
You need to note that it is indeed the smallest python program that can print its own source code but it is not a quine because a quine should not use לִפְתוֹחַ() פונקציה להדפיס את קוד המקור שלו.