Chris Pine’s Learn to Program

From Chris Pine’s Learn to Program

Write a program which asks for a person’s first name, then middle, then last. Finally, it should greet the person using their full name.

puts ‘What is your first name?’
first = gets.chomp
puts ‘What is your middle name?’
middle = gets.chomp
puts ‘What is your last name?’
last = gets.chomp
puts ‘Hello ‘ + first + ‘ ‘ + middle + ‘ ‘ + last + ‘!’

Write a program which asks for a person’s favorite number. Have your program add one to the number, then suggest the result as a bigger and better favorite number. 

puts ‘What is your favorite number?’
favorite_num = gets.chomp
better_num = favorite_num.to_i + 1
puts ‘Your favorite number is ‘ + favorite_num.to_s + ‘. How about ‘ + better_num.to_s + ‘ instead?’

Write a program which asks for a person’s first and last name and return the total number of letters in their full name.

puts ‘First name: ‘
first = gets.chomp
puts ‘Last name: ‘
last = gets.chomp
total_letters = first.length.to_i + last.length.to_i
puts ‘There are ‘ + total_letters.to_s + ‘ letters in your name.’

Write an Angry Boss program. It should rudely ask what you want. Whatever you answer, the Angry Boss should yell it back to you, and then fire you. For example, if you type in I want a raise., it should yell back WHADDAYA MEAN “I WANT A RAISE.”?!?  YOU’RE FIRED!!

puts ‘WHADDA FCK DO YOU WANT?’
answer = gets.chomp
puts ‘WHADDO U MEAN ‘ + ‘”‘ + answer + ‘”?!! YOU\’RE FIRED, BIATTTCH!’

Write a program which will display a Table of Contents so that it looks like this:

        Table of Contents      

Chapter 1:  Numbers                              page 1

Chapter 2:  Letters                                page 72

Chapter 3:  Variables                           page 118

lineWidth = 60
puts(‘Table of Content’.center(lineWidth))
puts(‘Chapter 1: Numbers’.ljust(lineWidth/2) + ‘page 1’.rjust(lineWidth/2))
puts(‘Chapter 2: Letters’.ljust(lineWidth/2) + ‘page 72’.rjust(lineWidth/2))
puts(‘Chapter 3: Variables’.ljust(lineWidth/2) + ‘page 118’.rjust(lineWidth/2))

Advertisements
Chris Pine’s Learn to Program

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s