Skip to content

Instantly share code, notes, and snippets.

@phlipper
Last active August 29, 2015 14:17
Show Gist options
  • Save phlipper/4f15ea048c188d06c68b to your computer and use it in GitHub Desktop.
Save phlipper/4f15ea048c188d06c68b to your computer and use it in GitHub Desktop.
TECH601-00 Day 4 Warmup
# Alice:
# id: ALI
# name: Alice
# birth date: April 4, 1977
# age: 37
# job title: Data Analyst
# interests: Communications, Keeping Secrets
# trustworthy?: yes
# 1. convert the specification for `Alice` into code, like we did last class
# with the country data
alice_id = "ALI"
alice_name = "Alice"
alice_birth_date = "April 4, 1977"
alice_age = 37
alice_job_title = "Data Analyst"
alice_interests = ["Communications", "Keeping Secrets"]
alice_trustworthy = true # boolean
# 2. use concatenation to create a message which reads:
# My name is _, and I work as a _.
message = "My name is " + alice_name + ", and I work as a " + alice_job_title + "."
# 3. output the previous message
puts message
# 4. use interpolation to output the following message, ending with a newline:
# I was born on _, and I will be _ years old on my next birthday.
puts "I was born on #{alice_birth_date}, and I will be #{alice_age + 1} years old on my next birthday."
# 5. if the person is trustworthy, output the following message:
# I have a total of _ interests, which include: _.
# otherwise, output the following message:
# This person cannot be trusted.
if alice_trustworthy
"I have a total of _ interests, which include: #{alice_interests}."
else
"This person cannot be trusted."
end
# 6. convert the following specification for `Bob` into code
#
# Bob:
# id: BOB
# name: Bob
# birth date: September 1, 1977
# age: 37
# job title: Software Engineer
# interests: Encryption, Constant Time Lookup, Quantum Computing
# trustworthy?: yes
bob_id = "BOB"
bob_name = "Bob"
bob_birth_date = "September 1, 1977"
bob_age = 37
bob_job_title = "Software Engineer"
bob_interests = "Encryption, Constant Time Lookup, Quantum Computing"
bob_trustworthy = true
# 7. perform steps 3 through 5 for Bob
# 2. use concatenation to create a message which reads:
# My name is _, and I work as a _.
message = "My name is " + bob_name + ", and I work as a " + bob_job_title + "."
# 3. output the previous message
puts message
# 4. use interpolation to output the following message, ending with a newline:
# I was born on _, and I will be _ years old on my next birthday.
puts "I was born on #{bob_birth_date}, and I will be #{bob_age + 1} years old on my next birthday."
# 5. if the person is trustworthy, output the following message:
# I have a total of _ interests, which include: _.
# otherwise, output the following message:
# This person cannot be trusted.
if bob_trustworthy
"I have a total of _ interests, which include: #{bob_interests}."
else
"This person cannot be trusted."
end
# 8. convert the following specification for `Eve` into code
#
# Eve:
# id: EVE
# name: Eve
# birth date: September 17, 1969
# age: 45
# job title: Cracker
# interests: Intercepting Communications
# trustworthy?: no
# 9. perform steps 3 through 5 for Eve
eve_id = "EVE"
eve_name = "Eve"
eve_birth_date = "September 17, 1969"
eve_age = 45
eve_job_title = "Cracker"
eve_interests = "Intercepting Communications"
eve_trustworthy = false
# 7. perform steps 3 through 5 for Bob
# 2. use concatenation to create a message which reads:
# My name is _, and I work as a _.
message = "My name is " + eve_name + ", and I work as a " + eve_job_title + "."
# 3. output the previous message
puts message
# 4. use interpolation to output the following message, ending with a newline:
# I was born on _, and I will be _ years old on my next birthday.
puts "I was born on #{eve_birth_date}, and I will be #{eve_age + 1} years old on my next birthday."
# 5. if the person is trustworthy, output the following message:
# I have a total of _ interests, which include: _.
# otherwise, output the following message:
# This person cannot be trusted.
if eve_trustworthy
"I have a total of _ interests, which include: #{eve_interests}."
else
"This person cannot be trusted."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment