{"id":1310,"date":"2013-07-28T23:46:28","date_gmt":"2013-07-29T03:46:28","guid":{"rendered":"http:\/\/www.a2life.info\/w\/?p=1310"},"modified":"2016-02-08T22:09:25","modified_gmt":"2016-02-09T03:09:25","slug":"ruby-%e3%81%a8%e3%80%80python","status":"publish","type":"post","link":"https:\/\/www.a2life.info\/w\/?p=1310","title":{"rendered":"Ruby \u3068\u3000Python"},"content":{"rendered":"<p>\u3069\u3061\u3089\u3082Interpreter\u3000Language\u3060\u304c\u3001\u3072\u3068\u3064\u3092\u9078\u3079\u3068\u8a00\u308f\u308c\u305f\u3089\u3069\u3061\u3089\u3092\u899a\u3048\u305f\u307b\u3046\u304c\u3088\u3044\u306e\u3060\u308d\u3046\u3002\u3000<br \/>\n\u65e5\u672c\u3067\u306fRuby\u304c\u304b\u306a\u308a\u4eba\u6c17\u304c\u3042\u308b\u3088\u3046\u3060\u304c\u3001Worldwide\u306eUser Base\u3067\u306fPython\u306e\u307b\u3046\u304c\u591a\u3044\u3002\u3000\u591a\u3044\u3068\u8a00\u3063\u3066\u3082PHP\u3068\u304b\u306b\u6bd4\u3079\u308b\u3068\u304b\u306a\u308a\u5c11\u306a\u3044\u3002<\/p>\n<p>Ruby<\/p>\n<pre>\r\n# Old \"coke\" program from 80's Basic programming book in Ruby\r\nanswer = Random.rand(1..100)\r\ncount,guess = 0,0\r\nputs 'I am thinking about number between 1 and 100. Can you guess?'\r\nwhile (answer != guess) \r\n  guess = gets.to_i\r\n  count += 1\r\n  if guess > answer \r\n     puts \"#{guess} is too high\"\r\n  elsif guess < answer\r\n     puts \"#{guess} is too low\"\r\n  else \r\n    puts \"you got it right in #{count} try!\"\r\n  end\r\nend\r\n<\/pre>\n<p>Python<\/p>\n<pre>\r\n\"\"\"Old \"coke\" program from 80's Basic programming book, in Python\"\"\"\r\nimport random\r\nanswer = random.randrange(1,100)\r\nprint (\"I am thinking a number between 1 and 100. Hope you can guess\")\r\nguess, count = 0,0\r\nwhile (answer != guess ):\r\n    guess = input (\"what number am I thinking? \")\r\n    guess = int(guess)\r\n    count += 1\r\n    if answer < guess:\r\n        print ( guess, \" is too high, try again\")\r\n    elif answer > guess:\r\n        print ( guess,\" is too low. Try again\")\r\n    else:\r\n        print (\"Bingo! you guessed it right in \",count,\" tries!\")\r\n<\/pre>\n<p>\u3068\u308a\u3042\u3048\u305a\u8abf\u3079\u3066\u898b\u3048\u3066\u304d\u305f\u90e8\u5206\u3067\u5927\u6614\u3001Basic\u3067\u521d\u671f\u306b\u66f8\u3044\u305f\u7df4\u7fd2\u7528\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u79fb\u690d\u3057\u3066\u307f\u305f\u304c\u3001\u3054\u3089\u3093\u306e\u3068\u304a\u308a\u3001\u3053\u308c\u304f\u3089\u3044\u306e\u30b5\u30a4\u30ba\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306a\u3089\u3001\u3069\u3061\u3089\u3067\u66f8\u3044\u3066\u3082\u307b\u3068\u3093\u3069\u5dee\u304c\u306a\u3044\u3002\u8a00\u8a9e\u306e\u30d1\u30ef\u30d5\u30eb\u306a\u3068\u3053\u308d\u3092\u4f7f\u3063\u3066\u307f\u306a\u3044\u3068\u305d\u306e\u5dee\u304c\u308f\u304b\u3089\u306a\u3044\u3001\u3068\u3044\u3046\u611f\u3058\u3060\u304c\u3001\u3000\u30eb\u30fc\u30ba\u306b\u884c\u304f\u306a\u3089Python\u304b\u306a\uff1f\u30a4\u30f3\u30c7\u30f3\u30c8\u3067\u30d6\u30ed\u30c3\u30af\u3092\u660e\u793a\u3057\u3066\u3044\u308b\u3001\u3064\u307e\u308a\u5358\u306a\u308b\u66f8\u5f0f\u3067\u306f\u306a\u304f\u3001\u8a00\u8a9e\u306e\u4e00\u90e8\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u304c\u3001\u306a\u3093\u3068\u3082\u5272\u308a\u5207\u3063\u3066\u3044\u308b\u3068\u3053\u308d\u3002\u3000\u3053\u308c\u3067\uff5b\uff5d\u3082\"End\"\u3082\u5fc5\u8981\u306a\u3044\u3002\u3000\u500b\u4eba\u7684\u306b\u306f\u597d\u304d\u3067\u3042\u308b\u3002\u3000\u3069\u3061\u3089\u306e\u8a00\u8a9e\u3082\u8aad\u307f\u89e3\u304d\u3084\u3059\u3044\u306e\u306f\u307e\u3061\u304c\u3044\u306a\u304f\u3001\u3053\u308c\u3092C++ \u3067\u66f8\u3053\u3046\u3068\u3059\u308b\u3068\u3001<\/p>\n<pre>\r\n#include &lt;iostream&gt;\r\n#include &lt;cstdlib&gt; \/\/need this to use rand() \r\n#include &lt;ctime&gt; \/\/need this to use time() \r\nusing namespace std;\r\n\r\nint main(){\r\n    int answer, guess=0, count=0;\r\n    srand(time(NULL));\r\n    answer = rand()%100 + 1;\r\n    cout << \"I am thinking about the number between 1 and 100. Can you guess?\";\r\n    while (guess != answer) {\r\n        ++count;\r\n        cin >> guess;\r\n        if (guess > answer) \r\n            cout << guess << \"is too high\";\r\n        else if (guess < answer) \r\n            cout << guess << \"is too low\";\r\n        else\r\n            cout <<\"You have it right in \" << count << \"  times!\";\r\n        cout << endl;\r\n                    \r\n    }\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u3053\u308c\u3088\u308a\u306f\u697d\u3067\u3059\u3088\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3061\u3089\u3082Interpreter\u3000Language\u3060\u304c\u3001\u3072\u3068\u3064\u3092\u9078\u3079\u3068\u8a00\u308f\u308c\u305f\u3089\u3069\u3061\u3089\u3092\u899a\u3048\u305f\u307b\u3046\u304c\u3088\u3044\u306e\u3060\u308d\u3046\u3002\u3000 \u65e5\u672c\u3067\u306fRuby\u304c\u304b\u306a\u308a\u4eba\u6c17\u304c\u3042\u308b\u3088\u3046\u3060\u304c\u3001Worldwide\u306eUser Base\u3067\u306fPython\u306e\u307b\u3046\u304c\u591a\u3044\u3002\u3000\u591a\u3044\u3068\u8a00\u3063\u3066\u3082PHP\u3068\u304b\u306b\u6bd4\u3079\u308b\u3068\u304b\u306a\u308a\u5c11\u306a\u3044\u3002 Ruby # Old &#8220;coke&#8221; program from 80&#8217;s Basic programming book in Ruby answer = Random.rand(1..100) count,guess = 0,0 puts &#8216;I am thinking about number between 1 and 100. Can you guess?&#8217; while (answer != guess) guess = gets.to_i count += 1 if guess > answer puts &#8220;#{guess} is too high&#8221; elsif guess < answer puts \"#{guess} is too low\" else puts \"you got it right in #{count} try!\" end end Python \"\"\"Old \"coke\" program from 80's Basic programming book, in Python\"\"\" import random answer = random.randrange(1,100) print (\"I am thinking a number between 1 and 100. Hope you can guess\") guess, count = 0,0 while (answer != &hellip; <a href=\"https:\/\/www.a2life.info\/w\/?p=1310\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,18],"tags":[41,42],"class_list":["post-1310","post","type-post","status-publish","format-standard","hentry","category-programming","category-18","tag-python","tag-ruby"],"_links":{"self":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1310"}],"version-history":[{"count":10,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1310\/revisions"}],"predecessor-version":[{"id":1312,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1310\/revisions\/1312"}],"wp:attachment":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}