The shoutbox is currently out of service. Join us on Discord instead.
You can help CodeWalrus stay online by donating here.

Unicorn's Ruby Questions and Programs [Ruby]

Started by Unicorn, July 18, 2015, 05:33:48 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Unicorn

December 08, 2015, 01:02:08 am #15 Last Edit: December 08, 2015, 05:24:53 am by Unicorn
I solved that, but now, I have another problem


require 'green_shoes'
q_num = 1
score = 0
unit1 = rand(1 .. 6)
unit2 = rand(1 .. 3)
if unit2 == 1
  type = "liquid"
end
if unit2 == 2
  type = "mass or weight"
end
if unit2 == 3
  type = "distance"
end
if unit1 == 1 && unit2 == 1
  q_ans = "Milliliter"
  q = 0.001
end
if unit1 == 1 && unit2 == 2
  q_ans = "Milligram"
  q = 0.001
end
if unit1 == 1 && unit2 == 3
  q_ans = "Millimeter"
  q = 0.001
end
if unit1 == 2 && unit2 == 1
  q_ans = "Centiliter"
  q = 0.01
end
if unit1 == 2 && unit2 == 2
  q_ans = "Centigram"
  q = 0.01
end
if unit1 == 2 && unit2 == 3
  q_ans = "Centimeter"
  q = 0.01
end
if unit1 == 3 && unit2 == 1
  q_ans = "Deciliter"
  q = 0.1
end
if unit1 == 3 && unit2 == 2
  q_ans = "Decigram"
  q = 0.1
end
if unit1 == 3 && unit2 == 3
  q_ans = "Decimeter"
  q = 0.1
end
if unit1 == 4 && unit2 == 1
  q_ans = "Dekaliter"
  q = 10
end
if unit1 == 4 && unit2 == 2
  q_ans = "Dekagram"
  q = 10
end
if unit1 == 4 && unit2 == 3
  q_ans = "Dekameter"
  q = 10
end
if unit1 == 5 && unit2 == 1
  q_ans = "Hectoliter"
  q = 100
end
if unit1 == 5 && unit2 == 2
  q_ans = "Hectogram"
  q = 100
end
if unit1 == 5 && unit2 == 3
  q_ans = "Hectometer"
  q = 100
end
if unit1 == 6 && unit2 == 1
  q_ans = "Kiloliter"
  q = 1000
end
if unit1 == 6 && unit2 == 2
  q_ans = "Kilolgram"
  q = 1000
end
if unit1 == 6 && unit2 == 3
  q_ans = "Kilometer"
  q = 1000
end
Shoes.app(title: "App", width: 500, height: 503) do
  background white
  @s = para "Score: #{score}/10", top: 200
  @qn = para "Question #{q_num} of 10", top: 300
  tagline "What is the correct unit?"
  para ""
  para ""
  @q = para "#{q} + #{type}"
  para ""
  @e = edit_line :top => 133, :width => 400
  button "Next" do
    if @e.text.capitalize != q_ans
      confrm = confirm ("Incorrect Answer. Next?")
      @q.remove
      unit1 = rand(1 .. 6)
      unit2 = rand(1 .. 3)
      if unit2 == 1
        type = "liquid"
      end
      if unit2 == 2
        type = "mass or weight"
      end
      if unit2 == 3
        type = "distance"
      end
      if unit1 == 1 && unit2 == 1
        q_ans = "Milliliter"
        q = 0.001
      end
      if unit1 == 1 && unit2 == 2
        q_ans = "Milligram"
        q = 0.001
      end
      if unit1 == 1 && unit2 == 3
        q_ans = "Millimeter"
        q = 0.001
      end
      if unit1 == 2 && unit2 == 1
        q_ans = "Centiliter"
        q = 0.01
      end
      if unit1 == 2 && unit2 == 2
        q_ans = "Centigram"
        q = 0.01
      end
      if unit1 == 2 && unit2 == 3
        q_ans = "Centimeter"
        q = 0.01
      end
      if unit1 == 3 && unit2 == 1
        q_ans = "Deciliter"
        q = 0.1
      end
      if unit1 == 3 && unit2 == 2
        q_ans = "Decigram"
        q = 0.1
      end
      if unit1 == 3 && unit2 == 3
        q_ans = "Decimeter"
        q = 0.1
      end
      if unit1 == 4 && unit2 == 1
        q_ans = "Dekaliter"
        q = 10
      end
      if unit1 == 4 && unit2 == 2
        q_ans = "Dekagram"
        q = 10
      end
      if unit1 == 4 && unit2 == 3
        q_ans = "Dekameter"
        q = 10
      end
      if unit1 == 5 && unit2 == 1
        q_ans = "Hectoliter"
        q = 100
      end
      if unit1 == 5 && unit2 == 2
        q_ans = "Hectogram"
        q = 100
      end
      if unit1 == 5 && unit2 == 3
        q_ans = "Hectometer"
        q = 100
      end
      if unit1 == 6 && unit2 == 1
        q_ans = "Kiloliter"
        q = 1000
      end
      if unit1 == 6 && unit2 == 2
        q_ans = "Kilolgram"
        q = 1000
      end
      if unit1 == 6 && unit2 == 3
        q_ans = "Kilometer"
        q = 1000
      end
      q_num = q_num + 1
      @q = para "#{q} + #{type}", top: 85
      @e.clear
      @e = edit_line :top => 133, :width => 400
      @qn.clear
     @qn = para "Question #{q_num} of 10", top: 300
      if confrm == false
        alert "You had a score of #{score}"
        exit
      end
    end
    if @e.text.capitalize == q_ans
      confrm = confirm ("Correct Answer. Continue?")
      if confrm == false
        alert "You had a score of #{score}"
        exit
      end
      if confrm == true
        @q.remove
        unit1 = rand(1 .. 6)
        unit2 = rand(1 .. 3)
        if unit2 == 1
          type = "liquid"
        end
        if unit2 == 2
          type = "mass or weight"
        end
        if unit2 == 3
          type = "distance"
        end
        if unit1 == 1 && unit2 == 1
          q_ans = "Milliliter"
          q = 0.001
        end
        if unit1 == 1 && unit2 == 2
          q_ans = "Milligram"
          q = 0.001
        end
        if unit1 == 1 && unit2 == 3
          q_ans = "Millimeter"
          q = 0.001
        end
        if unit1 == 2 && unit2 == 1
          q_ans = "Centiliter"
          q = 0.01
        end
        if unit1 == 2 && unit2 == 2
          q_ans = "Centigram"
          q = 0.01
        end
        if unit1 == 2 && unit2 == 3
          q_ans = "Centimeter"
          q = 0.01
        end
        if unit1 == 3 && unit2 == 1
          q_ans = "Deciliter"
          q = 0.1
        end
        if unit1 == 3 && unit2 == 2
          q_ans = "Decigram"
          q = 0.1
        end
        if unit1 == 3 && unit2 == 3
          q_ans = "Decimeter"
          q = 0.1
        end
        if unit1 == 4 && unit2 == 1
          q_ans = "Dekaliter"
          q = 10
        end
        if unit1 == 4 && unit2 == 2
          q_ans = "Dekagram"
          q = 10
        end
        if unit1 == 4 && unit2 == 3
          q_ans = "Dekameter"
          q = 10
        end
        if unit1 == 5 && unit2 == 1
          q_ans = "Hectoliter"
          q = 100
        end
        if unit1 == 5 && unit2 == 2
          q_ans = "Hectogram"
          q = 100
        end
        if unit1 == 5 && unit2 == 3
          q_ans = "Hectometer"
          q = 100
        end
        if unit1 == 6 && unit2 == 1
          q_ans = "Kiloliter"
          q = 1000
        end
        if unit1 == 6 && unit2 == 2
          q_ans = "Kilolgram"
          q = 1000
        end
        if unit1 == 6 && unit2 == 3
          q_ans = "Kilometer"
          q = 1000
        end
        q_num = q_num + 1
        @q = para "#{q} + #{type}", top: 85
        @e.clear
        @e = edit_line :top => 133, :width => 400
        score = score + 1
        @s.clear
        @qn.clear
        @s = para "Score: #{score}/10", top: 200
        @qn = para "Question #{q_num} of 10", top: 300
        if q_num == 11 && score == 10
          confrm = confirm("You have completed all of the questions with a score of #{score}! You got an A+! Try again?")
          if confrm == false
            exit
          end
          if confrm == true
            score = 0
            q_num = 0
          end
        end
        if q_num == 11
          confrm = confirm("You have completed all of the questions with a score of #{score}! You did not ace the quiz. Try again?")
          if confrm == false
            exit
          end
          if confrm == true
            score = 0
            q_num = 0
          end
        end
    end
  end
  end
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  button "Quit" do
    alert "You had a score of #{score}"
    exit
  end
  end


Anyhow, when it's run, it never asks for the Kilo prefix and meter suffix. I believe it has something to do with how I'm getting the rand, but I'm not sure. If someone could find out why its like that, it'd be great!

Oh yeah, and I'm sure there are a lot of things to be optimized, but I need to finish before optimizing. If you have any suggestions, please post them though.


Not sure what I did, but I fixed it! Updated the code



??? ??? ??? ??? ???

Unicorn

So, that same program is done, and I'm gonna release it!


require 'green_shoes'
q_num = 1
score = 0
unit1 = rand(1 .. 6)
unit2 = rand(1 .. 3)
if unit2 == 1
  type = "liquid"
end
if unit2 == 2
  type = "mass or weight"
end
if unit2 == 3
  type = "distance"
end
if unit1 == 1 && unit2 == 1
  q_ans = "Milliliter"
  q = 0.001
end
if unit1 == 1 && unit2 == 2
  q_ans = "Milligram"
  q = 0.001
end
if unit1 == 1 && unit2 == 3
  q_ans = "Millimeter"
  q = 0.001
end
if unit1 == 2 && unit2 == 1
  q_ans = "Centiliter"
  q = 0.01
end
if unit1 == 2 && unit2 == 2
  q_ans = "Centigram"
  q = 0.01
end
if unit1 == 2 && unit2 == 3
  q_ans = "Centimeter"
  q = 0.01
end
if unit1 == 3 && unit2 == 1
  q_ans = "Deciliter"
  q = 0.1
end
if unit1 == 3 && unit2 == 2
  q_ans = "Decigram"
  q = 0.1
end
if unit1 == 3 && unit2 == 3
  q_ans = "Decimeter"
  q = 0.1
end
if unit1 == 4 && unit2 == 1
  q_ans = "Dekaliter"
  q = 10
end
if unit1 == 4 && unit2 == 2
  q_ans = "Dekagram"
  q = 10
end
if unit1 == 4 && unit2 == 3
  q_ans = "Dekameter"
  q = 10
end
if unit1 == 5 && unit2 == 1
  q_ans = "Hectoliter"
  q = 100
end
if unit1 == 5 && unit2 == 2
  q_ans = "Hectogram"
  q = 100
end
if unit1 == 5 && unit2 == 3
  q_ans = "Hectometer"
  q = 100
end
if unit1 == 6 && unit2 == 1
  q_ans = "Kiloliter"
  q = 1000
end
if unit1 == 6 && unit2 == 2
  q_ans = "Kilogram"
  q = 1000
end
if unit1 == 6 && unit2 == 3
  q_ans = "Kilometer"
  q = 1000
end
Shoes.app(title: "Metric Ladder Quiz", width: 500, height: 503) do
  background white
  @s = para "Score: #{score}/10", top: 200
  @qn = para "Question #{q_num} of 10", top: 300
  tagline "What is the correct unit?"
  para ""
  para ""
  @q = para "#{q} + #{type}"
  para ""
  @e = edit_line :top => 133, :width => 400
  button "Next" do
    if @e.text.capitalize != q_ans
      confrm = confirm ("Incorrect Answer. Next?")
      @q.remove
      unit1 = rand(1 .. 6)
      unit2 = rand(1 .. 3)
      if unit2 == 1
        type = "liquid"
      end
      if unit2 == 2
        type = "mass or weight"
      end
      if unit2 == 3
        type = "distance"
      end
      if unit1 == 1 && unit2 == 1
        q_ans = "Milliliter"
        q = 0.001
      end
      if unit1 == 1 && unit2 == 2
        q_ans = "Milligram"
        q = 0.001
      end
      if unit1 == 1 && unit2 == 3
        q_ans = "Millimeter"
        q = 0.001
      end
      if unit1 == 2 && unit2 == 1
        q_ans = "Centiliter"
        q = 0.01
      end
      if unit1 == 2 && unit2 == 2
        q_ans = "Centigram"
        q = 0.01
      end
      if unit1 == 2 && unit2 == 3
        q_ans = "Centimeter"
        q = 0.01
      end
      if unit1 == 3 && unit2 == 1
        q_ans = "Deciliter"
        q = 0.1
      end
      if unit1 == 3 && unit2 == 2
        q_ans = "Decigram"
        q = 0.1
      end
      if unit1 == 3 && unit2 == 3
        q_ans = "Decimeter"
        q = 0.1
      end
      if unit1 == 4 && unit2 == 1
        q_ans = "Dekaliter"
        q = 10
      end
      if unit1 == 4 && unit2 == 2
        q_ans = "Dekagram"
        q = 10
      end
      if unit1 == 4 && unit2 == 3
        q_ans = "Dekameter"
        q = 10
      end
      if unit1 == 5 && unit2 == 1
        q_ans = "Hectoliter"
        q = 100
      end
      if unit1 == 5 && unit2 == 2
        q_ans = "Hectogram"
        q = 100
      end
      if unit1 == 5 && unit2 == 3
        q_ans = "Hectometer"
        q = 100
      end
      if unit1 == 6 && unit2 == 1
        q_ans = "Kiloliter"
        q = 1000
      end
      if unit1 == 6 && unit2 == 2
        q_ans = "Kilogram"
        q = 1000
      end
      if unit1 == 6 && unit2 == 3
        q_ans = "Kilometer"
        q = 1000
      end
      q_num = q_num + 1
      @q = para "#{q} + #{type}", top: 85
      @e.clear
      @e = edit_line :top => 133, :width => 400
      @qn.clear
      @qn = para "Question #{q_num} of 10", top: 300
      if confrm == false
        alert "You had a score of #{score}"
        exit
      end
    end
    if @e.text.capitalize == q_ans
      confrm = confirm ("Correct Answer. Continue?")
      if confrm == false
        alert "You had a score of #{score}"
        exit
      end
      if confrm == true
        @q.remove
        unit1 = rand(1 .. 6)
        unit2 = rand(1 .. 3)
        if unit2 == 1
          type = "liquid"
        end
        if unit2 == 2
          type = "mass or weight"
        end
        if unit2 == 3
          type = "distance"
        end
        if unit1 == 1 && unit2 == 1
          q_ans = "Milliliter"
          q = 0.001
        end
        if unit1 == 1 && unit2 == 2
          q_ans = "Milligram"
          q = 0.001
        end
        if unit1 == 1 && unit2 == 3
          q_ans = "Millimeter"
          q = 0.001
        end
        if unit1 == 2 && unit2 == 1
          q_ans = "Centiliter"
          q = 0.01
        end
        if unit1 == 2 && unit2 == 2
          q_ans = "Centigram"
          q = 0.01
        end
        if unit1 == 2 && unit2 == 3
          q_ans = "Centimeter"
          q = 0.01
        end
        if unit1 == 3 && unit2 == 1
          q_ans = "Deciliter"
          q = 0.1
        end
        if unit1 == 3 && unit2 == 2
          q_ans = "Decigram"
          q = 0.1
        end
        if unit1 == 3 && unit2 == 3
          q_ans = "Decimeter"
          q = 0.1
        end
        if unit1 == 4 && unit2 == 1
          q_ans = "Dekaliter"
          q = 10
        end
        if unit1 == 4 && unit2 == 2
          q_ans = "Dekagram"
          q = 10
        end
        if unit1 == 4 && unit2 == 3
          q_ans = "Dekameter"
          q = 10
        end
        if unit1 == 5 && unit2 == 1
          q_ans = "Hectoliter"
          q = 100
        end
        if unit1 == 5 && unit2 == 2
          q_ans = "Hectogram"
          q = 100
        end
        if unit1 == 5 && unit2 == 3
          q_ans = "Hectometer"
          q = 100
        end
        if unit1 == 6 && unit2 == 1
          q_ans = "Kiloliter"
          q = 1000
        end
        if unit1 == 6 && unit2 == 2
          q_ans = "Kilogram"
          q = 1000
        end
        if unit1 == 6 && unit2 == 3
          q_ans = "Kilometer"
          q = 1000
        end
        q_num = q_num + 1
        @q = para "#{q} + #{type}", top: 85
        @e.clear
        @e = edit_line :top => 133, :width => 400
        score = score + 1
        @s.clear
        @qn.clear
        @s = para "Score: #{score}/10", top: 200
        @qn = para "Question #{q_num} of 10", top: 300
        if q_num == 11 && score == 10
          confrm = confirm("You have completed all of the questions with a score of #{score}! You got an A+! Try again?")
          if confrm == false
            exit
          end
          if confrm == true
            score = 0
            q_num = 0
          end
        end
        if q_num == 11
          confrm = confirm("You have completed all of the questions with a score of #{score}! You did not ace the quiz. Try again?")
          if confrm == false
            exit
          end
          if confrm == true
            score = 0
            q_num = 0
          end
        end
      end
    end
  end
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  para ""
  button "Quit" do
    quit = confirm("Are you sure you want to quit?")
  if quit == true
    alert "You had a score of #{score}"
    exit
  end
  end
end


If you want to use it, download the file, and install ruby: https://www.ruby-lang.org/en/downloads/
After ruby is installed, open your terminal or cmd, and type:
[Windows] gem install green_shoes
[Linux] sudo gem install green_shoes
[OSX] Not sure, probably one of the two.

Example of play:

You get 2 hints, a number (.1, 100, 10, base ten) and you have to decide which metric name that is. 100 would be Hecto. You also get a substance (Liquid, mass, distance) and you have to name the metric unit for that. Liquid would be Liter. Put them together, and you get Hectoliter. That is your answer. Get all ten questions, and you get a cake. (not really)




??? ??? ??? ??? ???

Powered by EzPortal