From e99e57298172a7e27fddadc1ff2667f22444cd93 Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Mon, 23 May 2016 06:37:03 -0600 Subject: [PATCH 01/13] added external resource --- readme.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index b661e38..60bea15 100644 --- a/readme.md +++ b/readme.md @@ -320,9 +320,10 @@ Cheers! ### Resources 1. [Why I push for Python](http://lorenabarba.com/blog/why-i-push-for-python/) -2. [4 Reasons Why You Should Learn Ruby As Your First Programming Language](http://www.skilledup.com/learn/programming/4-reasons-learn-ruby-first-programming-language/) -3. [How do Python and Ruby compare?](http://www.quora.com/How-do-Python-and-Ruby-compare/answer/Fabio-Akita?share=1) -4. [Why Python is a Great First Language](http://blog.trinket.io/why-python/) -5. [Python vs Ruby](http://www.scriptrock.com/articles/python-vs-ruby) -6. [Ruby on Rails vs Python and Django: Which Should a Beginner Learn?](https://www.coursereport.com/resources/ruby-on-rails-vs-python-and-django-which-should-a-beginner-learn) -7. [Python Environment Management for Rubyists – a Guide](http://spin.atomicobject.com/2015/01/02/python-environment-mgmt/) \ No newline at end of file +1. [4 Reasons Why You Should Learn Ruby As Your First Programming Language](http://www.skilledup.com/learn/programming/4-reasons-learn-ruby-first-programming-language/) +1. [How do Python and Ruby compare?](http://www.quora.com/How-do-Python-and-Ruby-compare/answer/Fabio-Akita?share=1) +1. [Why Python is a Great First Language](http://blog.trinket.io/why-python/) +1. [Python vs Ruby](http://www.scriptrock.com/articles/python-vs-ruby) +1. [Ruby on Rails vs Python and Django: Which Should a Beginner Learn?](https://www.coursereport.com/resources/ruby-on-rails-vs-python-and-django-which-should-a-beginner-learn) +1. [Python Environment Management for Rubyists – a Guide](http://spin.atomicobject.com/2015/01/02/python-environment-mgmt/) +1. [Ruby vs Python](https://www.coursereport.com/blog/ruby-vs-python-choosing-your-first-programming-language) \ No newline at end of file From 50d47b43b938469c96a25a08de2a1438f8c923db Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Sun, 17 Jul 2016 13:58:44 -0600 Subject: [PATCH 02/13] Update readme.md --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 60bea15..9c46a11 100644 --- a/readme.md +++ b/readme.md @@ -319,6 +319,7 @@ Cheers! ### Resources +1. [Python vs Ruby](http://c2.com/cgi/wiki?PythonVsRuby) 1. [Why I push for Python](http://lorenabarba.com/blog/why-i-push-for-python/) 1. [4 Reasons Why You Should Learn Ruby As Your First Programming Language](http://www.skilledup.com/learn/programming/4-reasons-learn-ruby-first-programming-language/) 1. [How do Python and Ruby compare?](http://www.quora.com/How-do-Python-and-Ruby-compare/answer/Fabio-Akita?share=1) @@ -326,4 +327,4 @@ Cheers! 1. [Python vs Ruby](http://www.scriptrock.com/articles/python-vs-ruby) 1. [Ruby on Rails vs Python and Django: Which Should a Beginner Learn?](https://www.coursereport.com/resources/ruby-on-rails-vs-python-and-django-which-should-a-beginner-learn) 1. [Python Environment Management for Rubyists – a Guide](http://spin.atomicobject.com/2015/01/02/python-environment-mgmt/) -1. [Ruby vs Python](https://www.coursereport.com/blog/ruby-vs-python-choosing-your-first-programming-language) \ No newline at end of file +1. [Ruby vs Python](https://www.coursereport.com/blog/ruby-vs-python-choosing-your-first-programming-language) From 6e10ac84213b1090788c5db49f0a5ec2f47d1297 Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Thu, 22 Sep 2016 07:14:57 -0600 Subject: [PATCH 03/13] added resource --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 60bea15..7f63c43 100644 --- a/readme.md +++ b/readme.md @@ -326,4 +326,5 @@ Cheers! 1. [Python vs Ruby](http://www.scriptrock.com/articles/python-vs-ruby) 1. [Ruby on Rails vs Python and Django: Which Should a Beginner Learn?](https://www.coursereport.com/resources/ruby-on-rails-vs-python-and-django-which-should-a-beginner-learn) 1. [Python Environment Management for Rubyists – a Guide](http://spin.atomicobject.com/2015/01/02/python-environment-mgmt/) -1. [Ruby vs Python](https://www.coursereport.com/blog/ruby-vs-python-choosing-your-first-programming-language) \ No newline at end of file +1. [Ruby vs Python](https://www.coursereport.com/blog/ruby-vs-python-choosing-your-first-programming-language) +1. [Ruby vs Python, the Definitive FAQ](https://hackernoon.com/ruby-vs-python-the-definitive-faq-5cb0046292be) From b1b512dd08f2e029ec1939c2f226da7a8d2ccd95 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Tue, 4 Oct 2016 12:02:18 -0500 Subject: [PATCH 04/13] Refactoring ruby example to use ternary operator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As someone who writes Ruby regularly, the use of a return statement with a same-line if statement followed by a second default return seemed verbose and less readable. Plus, a one line ternary statement seems like a pretty good example of Ruby being Perl-like and a little unnecessarily complex to read for coders who don’t live with it every day. --- readme.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 6dc83ed..9948521 100644 --- a/readme.md +++ b/readme.md @@ -98,8 +98,7 @@ Let's compare some code. The following snippets of code are for solving the Fibo ```ruby def fib(n) - return n if n < 2 - fib(n-1) + fib(n-2) + n < 2 ? n : fib(n-1) + fib(n-2) end alias :fibonacci :fib ``` @@ -116,7 +115,7 @@ def fib(n): Although you can write this code in many ways, both of these methods are *true* to the language. -> The Ruby code demonstrates the practice of having multiple names for the same function (`fib` and `fibonacci` are the same). +> The Ruby code demonstrates the practices of using ternary operators and of having multiple names for the same function (`fib` and `fibonacci` are the same). In other words, the Ruby example is very Ruby-ish while the Python example is very Pythonic. Can you read the Ruby code? It may be more elegant but it's a bit harder to read. Meanwhile, it's easy to follow the Python code, right? You of course can write code anyway you want. It's advisable to write Ruby code, when beginning, in a more Pythonic way - which simply means making it more readable: From 74faff169674fc28ad5cb7249cfaad80c372b8dc Mon Sep 17 00:00:00 2001 From: Stefano Date: Sun, 9 Oct 2016 00:24:58 +0300 Subject: [PATCH 05/13] Fix typos --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 9948521..dd9af4a 100644 --- a/readme.md +++ b/readme.md @@ -129,7 +129,7 @@ def fib(n) end ``` -Keep in mind that in many cases with Python there are still a number of ways to do one thing. Take copying a list for example. There's a least four different ways: +Keep in mind that in many cases with Python there are still a number of ways to do one thing. Take copying a list for example. There are at least four different ways: ```python >>> my_list = [1,2,3] @@ -178,15 +178,15 @@ In the first example (Python), we are importing the `Twitter()` class from the ` #### Programming Paradigms -Again, you can use the same paradigms in both languages (procedural, functional, object oriented ...). When it comes to object oriented programming, Ruby used to have the upper hand, as it was built specifically for object orientation. That said, Python has moved more towards being a true object orientated language over the last few years. However, Ruby has one advantage, Ruby can add methods to existing classes, Python by default can't do this (although it's possible with the use of external libraries). +Again, you can use the same paradigms in both languages (procedural, functional, object oriented ...). When it comes to object oriented programming, Ruby used to have the upper hand, as it was built specifically for object orientation. That said, Python has moved more towards being a true object orientated language over the last few years. However, Ruby has one advantage: it can add methods to existing classes, while Python by default can't do this (although it's possible with the use of external libraries). #### Performance -Performance is a toss up as well. In some cases Python performs better, while in other cases, Ruby outperforms Python. It all depends on the task at hand. +Performance is a toss up as well. In some cases Python performs better, while in others Ruby outperforms Python. It all depends on the task at hand. #### Usage -Ruby has a bigger web presence with Rails than Python does with Django, so if you're looking to move into web development, Ruby may be the way to go. Python is a great general-purpose language and has more momentum going for it for areas outside outside of the web, such as sys admin/DevOps, statistics, and scientific computation. +Ruby has a bigger web presence with Rails than Python does with Django, so if you're looking to move into web development, Ruby may be the way to go. Python is a great general-purpose language and has more momentum going for it for areas outside of the web, such as sys admin/DevOps, statistics, and scientific computation. That said, take a look at the two code snippets below - @@ -204,7 +204,7 @@ End users do not care about the syntactical differences; they just want to see " #### Community -The Python community is active, vibrant, and truly helpful. Although, you can say the same about the Ruby community, the community itself is very much tied into Rails. If Rails is your thing, then you are in luck. +The Python community is active, vibrant, and truly helpful. Although you can say the same about the Ruby community, the community itself is very much tied into Rails. If Rails is your thing, then you are in luck. #### Popularity/Jobs From cda4fcb8cdbd3afc7b51bf8f93a49ddc81a006a9 Mon Sep 17 00:00:00 2001 From: Noah Rosamilia Date: Mon, 7 Aug 2017 12:35:16 -0400 Subject: [PATCH 06/13] Change all python code to python 3 --- guess.py | 18 +++++++++--------- readme.md | 28 ++++++++++++++-------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/guess.py b/guess.py index f68f125..3a28086 100644 --- a/guess.py +++ b/guess.py @@ -4,26 +4,26 @@ number = random.randint(1, 20) guesses = 0 -print 'Hello! What is your name?' -name = raw_input() +print('Hello! What is your name?') +name = input() -print "Hi, {}. I'm thinking of a number from 1 and 20.".format(name) +print("Hi, {}. I'm thinking of a number from 1 and 20.".format(name)) while guesses < 6: - print 'What is your guess. You have {} more guesses.'.format(6-guesses) - guess = raw_input() + print('What is your guess. You have {} more guesses.'.format(6-guesses)) + guess = input() guess = int(guess) guesses = guesses + 1 if guess < number: - print 'Too low.' + print('Too low.') elif guess > number: - print 'Too high.' + print('Too high.') elif guess == number: - print 'Good job, {}! You guessed my number in {} guesses!'.format(name,guesses) + print('Good job, {}! You guessed my number in {} guesses!'.format(name,guesses)) break if guess != number: - print 'Nope. The number I was thinking of was {}.'.format(number) + print('Nope. The number I was thinking of was {}.'.format(number)) diff --git a/readme.md b/readme.md index dd9af4a..fd086db 100644 --- a/readme.md +++ b/readme.md @@ -9,13 +9,13 @@ What do I mean by dynamic? Well, with a dynamically typed language you can do th ```sh >>> variable = 1 >>> type(variable) - + >>> variable = "Foo" >>> type(variable) - + >>> variable = ["bar",10] >>> type(variable) - + ``` Essentially, you can change the datatype (from an integer to a string to a list, in the above example) at any point in a program. In a statically typed language, this would result in an error when compiled. @@ -191,7 +191,7 @@ Ruby has a bigger web presence with Rails than Python does with Django, so if yo That said, take a look at the two code snippets below - ```python -print "Hello, World!" +print("Hello, World!") ``` and @@ -242,34 +242,34 @@ Guessing game ... ```python import random -import os + number = random.randint(1, 20) guesses = 0 -print 'Hello! What is your name?' -name = raw_input() +print('Hello! What is your name?') +name = input() -print "Hi, {}. I'm thinking of a number from 1 and 20.".format(name) +print("Hi, {}. I'm thinking of a number from 1 and 20.".format(name)) while guesses < 6: - print 'What is your guess. You have {} more guesses.'.format(6-guesses) - guess = raw_input() + print('What is your guess. You have {} more guesses.'.format(6-guesses)) + guess = input() guess = int(guess) guesses = guesses + 1 if guess < number: - print 'Too low.' + print('Too low.') elif guess > number: - print 'Too high.' + print('Too high.') elif guess == number: - print 'Good job, {}! You guessed my number in {} guesses!'.format(name,guesses) + print('Good job, {}! You guessed my number in {} guesses!'.format(name,guesses)) break if guess != number: - print 'Nope. The number I was thinking of was {}.'.format(number) + print('Nope. The number I was thinking of was {}.'.format(number)) ``` #### Ruby From 23b0a0d48f7edc4c32c9208646b607f244699511 Mon Sep 17 00:00:00 2001 From: neymarsabin Date: Mon, 21 Aug 2017 15:58:41 +0545 Subject: [PATCH 07/13] add picture of 2016 --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index fd086db..cdd08a5 100644 --- a/readme.md +++ b/readme.md @@ -208,6 +208,10 @@ The Python community is active, vibrant, and truly helpful. Although you can say #### Popularity/Jobs +![popularity](https://static1.squarespace.com/static/51361f2fe4b0f24e710af7ae/t/56b1187d4c2f85efc5598bb1/1454446752995/?format=750w) +Source: http://blog.codeeval.com/codeevalblog/2016/2/2/most-popular-coding-languages-of-2016 + + ![popularity](https://raw.github.com/mjhea0/python-ruby/master/images/codeeval2015.jpg) For the fourth year in a row, Python is the most popular language. Also, notice how Ruby decreased in popularity: From a6261564d9a35bababf377da892783141d2dc90c Mon Sep 17 00:00:00 2001 From: neymarsabin Date: Mon, 21 Aug 2017 16:03:08 +0545 Subject: [PATCH 08/13] fix a typo --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index cdd08a5..c087eaa 100644 --- a/readme.md +++ b/readme.md @@ -209,6 +209,7 @@ The Python community is active, vibrant, and truly helpful. Although you can say #### Popularity/Jobs ![popularity](https://static1.squarespace.com/static/51361f2fe4b0f24e710af7ae/t/56b1187d4c2f85efc5598bb1/1454446752995/?format=750w) + Source: http://blog.codeeval.com/codeevalblog/2016/2/2/most-popular-coding-languages-of-2016 From 3c9bce2c51507aac5d9dbb485725dc66718c274f Mon Sep 17 00:00:00 2001 From: Moritz Reiter Date: Tue, 23 Jan 2018 18:15:46 +0100 Subject: [PATCH 09/13] Fix typo --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c087eaa..95bc710 100644 --- a/readme.md +++ b/readme.md @@ -152,7 +152,7 @@ The difference is that there is one right way of doing this given the situation. ### More differences -As you can imagine, there are many more differences that just the syntax and philosophies of the two languages. Let's quickly look at some examples. +As you can imagine, there are many more differences than just the syntax and philosophies of the two languages. Let's quickly look at some examples. #### Learning Curve From 590c3d6728920f0fde4f10d45a6a5b55ac1b2212 Mon Sep 17 00:00:00 2001 From: Gurjus Bhasin <48339289+gsbhasin123@users.noreply.github.com> Date: Sat, 15 Feb 2020 15:37:41 -0800 Subject: [PATCH 10/13] Don't undermine python even though I'm a ruby guy --- guess.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/guess.py b/guess.py index 3a28086..569d019 100644 --- a/guess.py +++ b/guess.py @@ -7,11 +7,10 @@ print('Hello! What is your name?') name = input() -print("Hi, {}. I'm thinking of a number from 1 and 20.".format(name)) +print(f"Hi, {name}. I'm thinking of a number from 1 and 20.") while guesses < 6: - - print('What is your guess. You have {} more guesses.'.format(6-guesses)) + print(f'What is your guess? You have {6 - guesses} more guesses.') guess = input() guess = int(guess) @@ -22,8 +21,8 @@ elif guess > number: print('Too high.') elif guess == number: - print('Good job, {}! You guessed my number in {} guesses!'.format(name,guesses)) + print(f'Good job, {name}! You guessed my number in {guesses} guesses!') break if guess != number: - print('Nope. The number I was thinking of was {}.'.format(number)) + print(f'Nope. The number I was thinking of was {number}.') From 76898ea4d04d46ba9a80747aca0416168e93de9d Mon Sep 17 00:00:00 2001 From: tiosgz Date: Wed, 1 Dec 2021 20:11:06 +0000 Subject: [PATCH 11/13] Depythonize ruby example Some other rubyists may disagree with my version, & i encourage them to fix it. However, it's definitely more rubyish than the previous version. --- guess.rb | 26 ++++++++------------------ readme.md | 23 +++++++---------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/guess.rb b/guess.rb index 18a7c52..1c5bdf0 100644 --- a/guess.rb +++ b/guess.rb @@ -1,30 +1,20 @@ number = rand(1..20) -guesses = 0 puts 'Hello! What is your name?' -name = gets.chomp.to_s +name = gets&.chomp -puts "Hi, #{name}. I'm thinking of a number between 1 and 20." +puts "Hi, #{name}. I'm thinking of a number between 1 and 20." -while guesses < 6 +1.upto 6 do |guesses| + puts "What is your guess? You have #{7 - guesses} more guesses." + guess = gets&.chomp.to_i - puts "What is your guess? You have #{6-guesses} more guesses." - guess = gets.chomp.to_i - guesses += 1 - - unless guess == number - message = if guess > number - "Too high" - else - "Too low" - end - puts message - else + if guess == number puts "Good job, #{name}! You guessed my number in #{guesses} guesses." exit + else + puts(guess > number ? 'Too high' : 'Too low') end - end puts "Nope. The number I was thinking of was #{number}." - diff --git a/readme.md b/readme.md index 95bc710..79d2491 100644 --- a/readme.md +++ b/readme.md @@ -281,31 +281,22 @@ if guess != number: ```ruby number = rand(1..20) -guesses = 0 puts 'Hello! What is your name?' -name = gets.chomp.to_s +name = gets&.chomp puts "Hi, #{name}. I'm thinking of a number between 1 and 20." -while guesses < 6 - - puts "What is your guess? You have #{6-guesses} more guesses." - guess = gets.chomp.to_i - guesses += 1 +1.upto 6 do |guesses| + puts "What is your guess? You have #{7 - guesses} more guesses." + guess = gets&.chomp.to_i - unless guess == number - message = if guess > number - "Too high" - else - "Too low" - end - puts message - else + if guess == number puts "Good job, #{name}! You guessed my number in #{guesses} guesses." exit + else + puts(guess > number ? 'Too high' : 'Too low') end - end puts "Nope. The number I was thinking of was #{number}." From 21df6f91a6cf4fe0f946a61d162552c187c0f5d9 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Wed, 1 Dec 2021 20:15:06 +0000 Subject: [PATCH 12/13] Sync readme python example with guess.py --- readme.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 79d2491..f281cd9 100644 --- a/readme.md +++ b/readme.md @@ -255,11 +255,10 @@ guesses = 0 print('Hello! What is your name?') name = input() -print("Hi, {}. I'm thinking of a number from 1 and 20.".format(name)) +print(f"Hi, {name}. I'm thinking of a number from 1 and 20.") while guesses < 6: - - print('What is your guess. You have {} more guesses.'.format(6-guesses)) + print(f'What is your guess? You have {6 - guesses} more guesses.') guess = input() guess = int(guess) @@ -270,11 +269,11 @@ while guesses < 6: elif guess > number: print('Too high.') elif guess == number: - print('Good job, {}! You guessed my number in {} guesses!'.format(name,guesses)) + print(f'Good job, {name}! You guessed my number in {guesses} guesses!') break if guess != number: - print('Nope. The number I was thinking of was {}.'.format(number)) + print(f'Nope. The number I was thinking of was {number}.') ``` #### Ruby From 9f106cc3468f56a90d274d520db8622f98d7ea0c Mon Sep 17 00:00:00 2001 From: tiosgz Date: Wed, 1 Dec 2021 20:16:52 +0000 Subject: [PATCH 13/13] Make scripts executable --- guess.py | 2 ++ guess.rb | 2 ++ 2 files changed, 4 insertions(+) mode change 100644 => 100755 guess.py mode change 100644 => 100755 guess.rb diff --git a/guess.py b/guess.py old mode 100644 new mode 100755 index 569d019..8fb3b11 --- a/guess.py +++ b/guess.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + import random diff --git a/guess.rb b/guess.rb old mode 100644 new mode 100755 index 1c5bdf0..f15c2dc --- a/guess.rb +++ b/guess.rb @@ -1,3 +1,5 @@ +#!/usr/bin/env ruby + number = rand(1..20) puts 'Hello! What is your name?'