MIT : Ps0

Ps0 - First assignment

Intro to Computer Science and Programming
The assignment was to write a program in any language that asks the user for their last, then first name, then prints them back, first, then last. I first chose python, but then “translated” (ported?) my work to five other languages, below, being bash, lisp, tcl, perl, and ruby.
Pretty simple stuff, really, but then, this is the first assignment in an Intro course.

Understand, while I have done some coding (clearly, there are several programs on this site that I wrote), I am completely “self-taught”, at this stage, and far from being any thing remotely analogous to a seasoned or expert programmer. I AM learning as I do this. For the below scripts, for instance, I spent time googling and reading tutorials to understand how to port a solution in one language to another. I am not fluent in any of these computer languages. I have very moderate proficiency, perhaps, in bash and tcl. The rest are all basically new to me.

Python

First, a bite of py:

#!/usr/bin/env python
 
# first assignment for MIT intro comp sci class.
# Problem Set 0
# Name: Tony Baldwin
# Collaborators: none
# Time: 0:30
 
last = raw_input("Please enter your last name:  ")
first = raw_input("Please enter your first name: ")
print("Hello, " + first + " " +  last + "!")

screenshot

Bash

Now, for fun, let's translate that to bash.

#!/bin/bash
 
# MIT Intro to CS & Programming, assignment 1
# by tony baldwin
 
read -p "Please enter your last name: " last
read -p "Please enter your first name: " first
echo Hello, $first $last!

Lisp

Now, for giggles, let's try Lisp:

#!/usr/bin/clisp
 
; MIT Intro to CS & Programming, assignment 1
; tony baldwin
 
(format t "Please enter your last name: ")
    (let ((last (read)))
(format t "Please enter your first name: ")
     (let  ((first (read)))
     (format t "~%Hello, ~A ~A!" first last)))

Tcl

And, can't forget my first love, Tcl:

#!/usr/bin/env tclsh8.5
 
# MIT Intro to CS & Programming, assignment 1
# by tony baldwin
 
puts "Please enter your last name: "
gets stdin last
puts "Please enter your first name: "
gets stdin first
puts "Hello, $first $last!"

mit-ps0pyall.jpg


That's all I've got for now.
Maybe later I should try perl.

tonybaldwin August 31, 2011, at 08:31 PM


Perl

Okay, added perl:

#!/usr/bin/perl -w
# use strict;
 
# MIT Intro to CS & Prog
# assignment PS0
 
print "Please enter your last name: ";
chomp($last = <stdin>);
print "Please enter your first name: ";
chomp($first = <stdin>);
print "Hello, $first $last!\n";

I don't pretend to have any real perl fu, but this works. :)

Ruby

And, how about some ruby?

#!/usr/bin/ruby
 
# MIT Intro to CS & Programming
# assignment ps0
 
puts "Please enter your last name: "
last = gets
puts "Please enter your first name: "
first = gets
puts "Hello, " + first.chomp + " " +  last.chomp + "!"

tonybaldwin September 01, 2011, at 06:51 AM


~~DISQUS~~