This file contains 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
# an empty array to store the grades | |
grades = [] | |
# variables for the passing grade and the total number of subjects. You can change them from here. | |
pass_grade = 50 | |
subjects = 7 | |
# loops until reaches the the number of subjects on the subjects variable | |
while grades.count < subjects | |
# prints the message |
This file contains 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
# A method that takes one array of any size as an argument and prints faild when the average total grades is 50 or more and pass when its less than 50 | |
def calculate(grades) | |
# countes the number of objects in the array and assign it to subjects varible to use it latter for calculating the average | |
subjects = grades.count | |
# sums all of the array objects and assign them to the varible sum | |
sum = grades.inject(:+) | |
# compares sum with the passing grade and prints the resuts | |
if sum / subjects >= 50 | |
puts "Faild" |
This file contains 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
puts "hEllo My DeAr".upcase | |
puts "hEllo My DeAr".downcase |
This file contains 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
def upcase_words(words) | |
puts "#{words}".upcase | |
end | |
def downcase_words(words) | |
puts "#{words}".downcase | |
end | |
downcase_words("hEllo My DeAr") |
This file contains 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
def letter_count(words, letter) | |
if words.include?(letter) | |
count = words.count(letter) | |
puts "The letter #{letter} appears #{count} time(s)" | |
else | |
puts "The letter #{letter} did not appear in '#{words}'" | |
end | |
end | |
# test |
This file contains 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
puts 'How many units did you achive?' | |
total_units = gets.to_i | |
# validations for the input format | |
if total_units == 0 | |
puts 'Please enter a number that is greater than 0.' | |
end | |
#Counters | |
total_points = 0 | |
submited_counter = 0 |
This file contains 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
#!/usr/bin/ruby | |
class TimeSheet | |
attr_accessor(:start_time, :finish_time, :launch, :breaks, :meeting) | |
def input | |
week = ['Monday', 'Tuesday','Wednesday', 'Thursday','Friday','Saturday','Sunday' ] | |
week.each do |d| | |
puts "What time did you start? on " + d | |
@start_time = gets | |
puts "What time did you finish working? on " + d |
This file contains 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
# Make a todo list | |
list = [] | |
# print the list | |
def show_items(): | |
print("Your current list has the times:") | |
for item in list: | |
print(item) | |
# add new tiems to the list |
This file contains 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
def game(): | |
# import random | |
import random | |
# generate a random number | |
secrit_num = random.randint(1, 10) | |
# count the attepts to guess | |
attempts = 0 |
This file contains 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
import sys | |
import random | |
import os | |
good_guesses = [] | |
bad_guesses = [] | |
def start(): | |
clear() | |
print(game) |
OlderNewer