Ruby Programming - 13 - Pythagorean Theorem Calculator

Поделиться
HTML-код
  • Опубликовано: 13 дек 2024

Комментарии • 27

  • @Jake-Day
    @Jake-Day  10 лет назад +14

    Here's a great sample of what to expect from my Ruby programming course. In this lesson we'll be making a program that finds the area of a triangle. After that we'll build a simple Pythagorean theorem calculator.

  • @FernandoTheBeast28
    @FernandoTheBeast28 10 лет назад +1

    print "Doe! What is the base of your trap(tapezoid)?"
    a = gets.to_f;
    print "What is the second base of your trap?"
    b = gets.to_f;
    print "What is the height of your trap?"
    h = gets.to_f;
    fee = a + b
    fi = fee / 2
    foe = fi * h
    puts "The area of your trap is #{foe}"
    LOL I thought I would share
    Thank you, Jake (from StateFarm)!

  • @wavvvesvvvves4175
    @wavvvesvvvves4175 9 лет назад +1

    Hey Jake I did this lesson. Then the gears in my brain started turning and I condensed this lesson down to about 2 lines of code. Granted I've been studying on codecademy, ruby monk, and beginning ruby (the book) as well as these lessons but still. I was excited I was able to do that because it means progress is being made! Anyway here's the code:
    def hypo_calc(num, num_1)
    num2 = num ** 2 + num_1 ** 2
    puts "Your triangle's hypotenuse is #{Math.sqrt(num2).round}"
    end
    hypo_calc(4, 3)

    • @carlevans475
      @carlevans475 9 лет назад

      +wavvves vvvves great work, keep it up :)

  • @TheNakkytakky
    @TheNakkytakky 8 лет назад

    Hello Jake,
    I was going through your tutorials with ruby. The first 12 went flawless, this 13th got me a strange error I couldn't solve. Maybe you or someone else could?
    Code:
    puts "This is a pythagorean theorem calculator ! You can find the hypotenus of a right triangle with it."
    print "To get started, what is side a?"
    a = gets.to_f;
    puts "what is side b of your triangle?"
    b = gets.to.f;
    a2 = a**2.
    b2 = b**2.
    c2 = (a2*b2)
    puts "you look great today! By the way, your triangle's hypotenuse is #{Math.sqrt(c2)}"
    Error(I also get this error using notepad and ruby command):
    his is a pythagorean theorem calculator ! You can find the hypotenus of a right triangle with it.
    To get started, what is side a?20
    what is side b of your triangle?
    30
    C:/Users/Nick/RubymineProjects/untitled1/pythagorean.rb:7:in `': undefined method `to' for "30
    ":String (NoMethodError)
    from -e:1:in `load'
    from -e:1:in `'

  • @longb1913
    @longb1913 8 лет назад +1

    Why do you need the semi-colon? does it matter whether it is there or not?

  • @ricoferdianalexander7069
    @ricoferdianalexander7069 10 лет назад +1

    I'm sorry I want to ask something, when you said that after gets.to_f there should be a semicolon at the end of it, but I accidentally tried it like this :
    a = gets.to_f

  • @aly5459
    @aly5459 10 лет назад

    Hi jacob its great!
    But how do you connect Triangles area with hypotenuse in one code? like the program have given you the results of triangle code and asking you about if you want to proceed the hypotenuse calculation ? it will be great if you could say me how i do it in one notepad code.

  • @yvignygoncharov4642
    @yvignygoncharov4642 9 лет назад

    So I take it the point of using 0.5*h*w instead of the much more obvious h*w/2 is because it forces "area" to be float?

  • @desmondade
    @desmondade 8 лет назад

    hey Jake! thanks alot for this great tutorials its very helpful, please can you please give me a clear difference between "print"and "puts"

  • @dmytro_palahniuk
    @dmytro_palahniuk 9 лет назад

    hehe, this is pretty neat, I've coded my first program! Thanks, man!

  • @zusegaming401
    @zusegaming401 9 лет назад

    Wild Academy When ever i try and make the number round they dont round i keep geting the same numbers every time how do u fix this?
    This is what i put
    puts "You are looking great today! By the way your triangle hypotenuse is #{ Math.sqrt (2).round"
    did i type something wrong in the line??Thanks

  • @nicandromartinezsotelo3300
    @nicandromartinezsotelo3300 10 лет назад

    Hello,
    Been meaning to ask you, how do you prepare for an interview for a RoR junior developer position?
    Thanks

    • @Jake-Day
      @Jake-Day  10 лет назад +1

      Find someone in the company that will vouch for you. Go to RoR meetups. Ask people about themselves. If someone says you're a cool dude or gal, it increases your chances of being hired 10X.
      Not doing that, drink a glass of wine before you go in. Not too much now. Just enough to make you feel like a nice warm person. The placebo effect will kick in to cover the rest. Brush your teeth after. Some people have a good sense of smell, especially if the interviewer is a pregnant woman. (Not sure why I needed to specify the gender of a pregnant person.) Ditch the wine completely if that's the case. Just go with the champagne after you get the job. Also, if you're like me and get red rashes around the eyes when drinking wine, just forget about it. Good luck.

  • @generatormark1996
    @generatormark1996 10 лет назад

    when do you use puts and when prints?

    • @noahspagnolo6741
      @noahspagnolo6741 10 лет назад +2

      When you use puts, the text goes into a new line
      puts "I am anonymous"
      puts "Yes, I am"
      Outputs: I am anonymous
      Yes, I am
      -----------------------------------------------
      Print does everything in the same line
      print "I am anonymous"
      print "Yes, I am"
      Outputs: I am anonymous Yes, I am
      ------------------------------------------------------
      Hope it makes sense.

    • @generatormark1996
      @generatormark1996 10 лет назад

      Noah Spagnolo It does make sense, thanks for explaining to me :)

  • @varunupadhyay3836
    @varunupadhyay3836 10 лет назад +1

    I like watching your Ruby tutorial videos and they are really helpful. Can you please post a link to your interview with the programmer which you mentioned in Day12 video?
    Thank you.

  • @jorgepena8508
    @jorgepena8508 10 лет назад

    //I tried:
    puts "The triangle's hypotenuse is #{Math .sqrt(c2).round(2)}"
    //and I got an error message:
    19.rb:11:in `round': wrong number of arguments (1 for 0) (ArgumentError)
    from 19.rb:11
    //...WHY?

    • @LuisFlores-ls4yy
      @LuisFlores-ls4yy 10 лет назад

      The reason you are getting this argument is prior versions of ruby that are before version 1.9 aren't able to interpret it. You need to get the 1.93 version to resolve this issue.

  • @Kewendi
    @Kewendi 10 лет назад

    Why do I need a semi colon at the end of the to_f; ??

  • @zusegaming401
    @zusegaming401 9 лет назад

    never mind i just rerote the line and it worked idk what it was but i fixed it
    :)

  • @yvignygoncharov4642
    @yvignygoncharov4642 9 лет назад

    "hypotenuse", BTW.

  • @havardnygard9252
    @havardnygard9252 10 лет назад

    Why do the teacher do mistakes i dont do :P

    • @Jake-Day
      @Jake-Day  10 лет назад +3

      Because you have the eye of the tiger. Survivor - Eye Of The Tiger

    • @havardnygard9252
      @havardnygard9252 10 лет назад +1

      Nice one :P