2
短版本就是問題。是否有Python 2的等效Javascripts confirm()命令?
較長版本: 我通過Codecademy學習Javascript,同時嘗試重新學習Python 2。我剛剛完成了「選擇你自己的冒險故事」。
在下面的代碼,我可以找出如何輕鬆地在2號線
// Check if the user is ready to play!
confirm("It's gametime!");
var age = prompt("What's your age");
if (age < 13)
{
console.log("You're really young, but go play");
}
else
{
console.log("You're old enough. Start playing");
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer = prompt("Do you want to race Bieber on stage?");
if (userAnswer === "yes")
{
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
else
{
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}
var feedback = prompt("Rate this game from 1-10");
if (feedback > 8)
{
console.log("Thank you! We should race at the next concert!");
}
else
{
console.log("I'll keep practicing coding and racing.");
}
調整一切到Python 2除了代碼除確認命令我會很感激的任何幫助。非常感謝。
你爲什麼要無視'確認()的返回值'打電話?如果你不能取消,爲什麼要使用它? Python沒有這樣的對話框,你可以創建一個函數,要求輸入'yes'或'no',參見[詢問用戶輸入,直到他們給出有效響應](http://stackoverflow.com/q/23294658)尋求這些功能的幫助。 –
如果你想要一個GUI對話框,你可以使用'tkinter'的'askyesno()'函數。 – TigerhawkT3