Last active
July 30, 2018 18:26
-
-
Save sheland/256278504470ca58ef613f2081e824ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #How would you modify the code below to improve the code style and readability? | |
| foods = ["shrimp", "cauliflower", "salmon", "garlic", "oysters", | |
| "salami", "tomatoes", "okra", "zucchini", "avocado"] | |
| print "How many foods would you like to see? I suggest 10, but it's up to you. " | |
| items = gets.chomp.to_i | |
| if items > 10 | |
| puts "Best I can do is 10. Let's do 10." | |
| items = 10 | |
| elsif items >= 1 && items <= 10 | |
| puts "Ok! Let's do " + items.to_s + "." | |
| else | |
| puts "We'll just pretend you said 10." | |
| items = 10 | |
| end | |
| puts "...Your Fancy Random Menu..." | |
| items.times do |i| | |
| y = foods[rand(0...(foods.length))] | |
| puts i.to_s+": " + y | |
| end | |
| #Bio Program | |
| #Create a program that accepts input from the user and outputs a bio with that information | |
| #Use up to five different attributes about the person to populate the bio | |
| #Output should consist of a paragraph of output created from the users input | |
| #Prints out welcome message to user | |
| print "Welcome to the bio creater game. Tell me about yourself!\n" | |
| #Input user's data | |
| print "Enter name: " | |
| name = gets.chomp | |
| print "When is your birthday?\n" | |
| puts "Enter the month in number form: " | |
| month = gets.chomp.to_i | |
| print "Enter the date: " | |
| date = gets.chomp.to_i | |
| print "Enter the year: " | |
| b_year = gets.chomp.to_i | |
| print "Enter your occupation: " | |
| job = gets.chomp.upcase | |
| #calulation to figure out age of user | |
| current_time = Time.now | |
| birth_date = Time.new(b_year, month, date) | |
| age = (current_time.year - birth_date.year).to_i | |
| #Outputs a short bio from user's input in paragraph form | |
| print "Here is your short bio.....\n\n\n" | |
| "#{name.capitalize} is a(n) #{job} who was born on #{month} #{date}, #{b_year}. | |
| #{name.capitalize} is #{age} years old." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment