如何将此python代码转换为Javascript

时间:2017-03-29 04:42:40

标签: javascript python

我不想在Javascript中运行Python代码,我想将其完全转换为JS代码。我不知道python,Can body可以帮助我。谢谢。

print ("Please input the # of books you've read this year") 
BooksAlready=int(input())
print ("Please input the # of weeks that have already passed this year") 
WeeksAlready=int(input())
x=(78/52)
c=x*WeeksAlready-BooksAlready
if (BooksAlready/WeeksAlready)>x:
  print ("You're on point, go have some fun!")
else:
  print ("Go read, you piece of uneducated crap")
  print ("You have")
  print (c)
  print ("books left to read this week to get on point")

2 个答案:

答案 0 :(得分:1)

这将在浏览器的js控制台中运行。 prompt在node.js中不起作用,您可以使用process.argv访问命令行参数。

console.log("Please input the # of books you've read this year");
console.log("Please input the # of weeks that have already passed this year");

var WeeksAlready=parseInt(prompt()),
BooksAlready=parseInt(prompt()), 
x=(78/52),
c=x*WeeksAlready-BooksAlready;

if (BooksAlready/WeeksAlready>x){
    console.log("You're on point, go have some fun!");
}
else{
   console.log ("Go read, you piece of uneducated crap");
   console.log ("You have");
   console.log (c);
   console.log ("books left to read this week to get on point"); 
}

答案 1 :(得分:0)

请查看以下链接,了解有关从python到js的转换器的更多信息。

http://www.infoworld.com/article/3033047/javascript/4-tools-to-convert-python-to-javascript-and-back-again.html