Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1 Guessing number game
- puts "Welcome to the guessing play number game!"
- # Generate a random number between 0 – 1000 (including 0, but not including 1000)
- random = rand(0...1)
- puts "Enter a number between 0 and 1000 here: "
- guessing = gets.chomp.to_i
- i = 1
- while guessing != random
- if guessing < random
- puts "HIGHER"
- guessing = gets.chomp.to_i
- elsif guessing > random
- puts "LOWER"
- guessing = gets.chomp.to_i
- end
- i += 1
- end
- if guessing == random
- puts "YOU GOT IT IN #{i} GUESSES!"
- end
- # 2 Duck duck goose game
- puts "Welcome to the duck duck goose game!"
- puts "Which player do you want to Goose? "
- player = gets.chomp.to_i
- i = 1
- while i != player
- puts "Player #{i}: Duck"
- i += 1
- end
- if i == player
- puts "Player #{i}: Goose"
- end
- # 3 Petals on a flower game
- puts "Welcome to the petals on a flower game!"
- puts "How many petals does the flower have?"
- petals = gets.chomp.to_i
- i = 1
- while i != petals
- if i % 2 == 0
- puts "Plucking petal #{i}: they love me not!"
- else
- puts "Plucking petal #{i}: they love me!"
- end
- i += 1
- end
- if i == petals
- if i % 2 == 0
- puts "Plucking petal #{i}: they love me not! sad!"
- else
- puts "Plucking petal #{i}: they love me! happy!"
- end
- end
- # 4 Testing users
- puts "Hello! We are going to total some numbers!"
- puts "Enter a negative number to quit."
- total = 0
- puts "Enter a number here: "
- input1 = gets.chomp.to_i
- puts "Confirm your number here"
- input2 = gets.chomp.to_i
- while input1 != input2
- puts "Enter a number here: "
- input1 = gets.chomp.to_i
- puts "Confirm your number here"
- input2 = gets.chomp.to_i
- end
- while input1 > -1
- total += input1
- puts "Enter a number here: "
- input1 = gets.chomp.to_i
- puts "Confirm your number here"
- input2 = gets.chomp.to_i
- while input1 != input2
- puts "Enter a number here: "
- input1 = gets.chomp.to_i
- puts "Confirm your number here"
- input2 = gets.chomp.to_i
- end
- end
- puts "Result: #{total}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement