SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 1 Guessing number game
  2. puts "Welcome to the guessing play number game!"
  3. # Generate a random number between 0 – 1000 (including 0, but not including 1000)
  4. random = rand(0...1)
  5.  
  6. puts "Enter a number between 0 and 1000 here: "
  7. guessing = gets.chomp.to_i
  8.  
  9. i = 1
  10. while guessing != random
  11.     if guessing < random
  12.         puts "HIGHER"
  13.         guessing = gets.chomp.to_i
  14.     elsif guessing > random
  15.         puts "LOWER"
  16.         guessing = gets.chomp.to_i
  17.     end
  18.     i += 1
  19. end
  20.  
  21. if guessing == random
  22.     puts "YOU GOT IT IN #{i} GUESSES!"
  23. end
  24.  
  25. # 2 Duck duck goose game
  26. puts "Welcome to the duck duck goose game!"
  27. puts "Which player do you want to Goose? "
  28. player = gets.chomp.to_i
  29.  
  30. i = 1
  31. while i != player
  32.     puts "Player #{i}: Duck"
  33. i += 1
  34. end
  35.  
  36. if i == player
  37.     puts "Player #{i}: Goose"
  38. end
  39.  
  40. # 3 Petals on a flower game
  41.  
  42. puts "Welcome to the petals on a flower game!"
  43. puts "How many petals does the flower have?"
  44. petals = gets.chomp.to_i
  45.  
  46. i = 1
  47. while i != petals
  48.     if i % 2 == 0
  49.         puts "Plucking petal #{i}: they love me not!"
  50.     else
  51.         puts "Plucking petal #{i}: they love me!"
  52.     end
  53. i += 1
  54. end
  55.  
  56. if i == petals
  57.     if i % 2 == 0
  58.         puts "Plucking petal #{i}: they love me not! sad!"
  59.     else
  60.         puts "Plucking petal #{i}: they love me! happy!"
  61.     end
  62. end
  63.  
  64. # 4 Testing users
  65.  
  66. puts "Hello! We are going to total some numbers!"
  67. puts "Enter a negative number to quit."
  68.  
  69. total = 0
  70. puts "Enter a number here: "
  71. input1 = gets.chomp.to_i
  72. puts "Confirm your number here"
  73. input2 = gets.chomp.to_i
  74. while input1 != input2
  75.     puts "Enter a number here: "
  76.     input1 = gets.chomp.to_i
  77.     puts "Confirm your number here"
  78.     input2 = gets.chomp.to_i
  79. end
  80. while input1 > -1
  81.     total += input1
  82.     puts "Enter a number here: "
  83.     input1 = gets.chomp.to_i
  84.     puts "Confirm your number here"
  85.     input2 = gets.chomp.to_i
  86.     while input1 != input2
  87.         puts "Enter a number here: "
  88.         input1 = gets.chomp.to_i
  89.         puts "Confirm your number here"
  90.         input2 = gets.chomp.to_i
  91.     end
  92. end
  93.    
  94. puts "Result: #{total}"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top