Python Program - Solve a Quadratic Equation

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

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

  • @SharnavTech
    @SharnavTech  4 года назад +7

    Download Source Code:- bit.ly/3NMai3P
    • *Please Be Sure To Like this video, and Subscribe to my Channel*
    ===================================================
    *◘ My other Programming Tutorials →*
    My Python Tutorial Playlist : tiny.cc/amwaqz
    Print squares of numbers from 1 to x (Java): ruclips.net/video/L5wlwj8P06M/видео.html
    Multiplication Tables of Number (Java): ruclips.net/video/BhVJtQJFxNQ/видео.html
    Auto Typer (Visual Basic Script): ruclips.net/video/g1uI31Ck_DM/видео.html
    Prank Virus (Visual Basic Script): ruclips.net/video/Uz7WxR-iteA/видео.html
    ===================================================
    *• Some of my How-to Tutorials →*
    Add Custom Theme to IDLE: ruclips.net/video/JG9GedugQ1A/видео.html
    Change OEM information on Windows: ruclips.net/video/PeU7YsLH6cE/видео.html
    Add Icons to Folders: ruclips.net/video/XEPFr2UsI44/видео.html
    Change skin of your mouse cursor: ruclips.net/video/JG9GedugQ1A/видео.html
    Download RUclips videos using VLC: ruclips.net/video/Jo0kygEzUz0/видео.html
    Change Lockscreen Background in Windows 7: ruclips.net/video/zyumc20nH50/видео.html

    • @anilkumarsharma8901
      @anilkumarsharma8901 Год назад

      give me html version for all this so its become interective and we make parabola according to given conditions

  • @pizza3454
    @pizza3454 2 года назад +30

    Dude, thank you. Just finished my homework!

    • @SharnavTech
      @SharnavTech  2 года назад

      Welcome :)

    • @pizza3454
      @pizza3454 2 года назад

      @@SharnavTech Hey, do you mind explaining what line 9 and 10 do? Didn't get that part.

    • @SharnavTech
      @SharnavTech  2 года назад

      Can you please just point out the timestamp in the video?

    • @pizza3454
      @pizza3454 2 года назад

      @@SharnavTech 4:39 and the one after.

    • @SharnavTech
      @SharnavTech  2 года назад +1

      @Pizza345 print("
      ") is used to print an empty line.
      is an escape character, that is used to break a line.
      The next line just prints a statement. It uses an f-string, which is used to substitute value of a variable (inside { }) without concatenating the string. Its an alternative to string's format() method. Read more here - www.geeksforgeeks.org/formatted-string-literals-f-strings-python/amp/

  • @pralayrana2187
    @pralayrana2187 2 года назад +3

    Thank u bro! I was getting problem in complex no. but now it is solved. Thanks again!!

  • @botgg7310
    @botgg7310 Год назад +3

    I just finished my class work thank you

  • @ascendedmemequeen925
    @ascendedmemequeen925 2 года назад +2

    you just saved my life, thank you

  • @dawoodaltai6113
    @dawoodaltai6113 3 года назад +4

    I like your explanation 😇

  • @yagomizuma2275
    @yagomizuma2275 2 года назад +1

    tip: put it in a while statement where r= int(input()) and while r>0 run the code above for homeworks then r=r-1

    • @yagomizuma2275
      @yagomizuma2275 2 года назад

      SORRY GUYS AN WHILE STATEMENT

    • @SharnavTech
      @SharnavTech  2 года назад

      So you mean to ask user how many times they want to run the code, and use while loop for that?

    • @yagomizuma2275
      @yagomizuma2275 2 года назад

      @@SharnavTech yeah

  • @oversipelio983
    @oversipelio983 9 месяцев назад +2

    great, thanks Sharnav

  • @user-en1vt4cr2w
    @user-en1vt4cr2w Год назад +2

    Hello,
    Why I don't have the roots' results in the end?
    I followed all the steps and when I try to run the program the final line writes: Type of Roots: Two Distinct Real Roots
    Thank you in advance!

    • @SharnavTech
      @SharnavTech  Год назад

      Check if you didn't forget to print the roots...If you didn't then contact me on Instagram (@techy_sharnav) or Discord (TechySharnav#1615) with the code

  • @obinnachika5096
    @obinnachika5096 Год назад +1

    Thanks alot 🤝🏿

  • @sanatathera5531
    @sanatathera5531 Год назад +1

    Thanks, very helpful!

  • @manvithah8271
    @manvithah8271 2 года назад +1

    Thank you,nice demonstrate

  • @gauravsavlani5725
    @gauravsavlani5725 2 года назад +2

    thank you

  • @mominsiddiqui6927
    @mominsiddiqui6927 2 года назад +1

    Hello Sharnav, I dont seem to understand why my program is not running. I believe that I followed your instructions precisely. please let me know what I did wrong.

    • @mominsiddiqui6927
      @mominsiddiqui6927 2 года назад

      This is what I got
      import cmath
      >>> print("General Form: - a**2 + bx + c = 0")
      General Form: -a**2 + bx + c = 0
      >>> a = int(input("Enter a (a != 0): "))
      Enter a (a != 0): 1
      >>> b = int(input("Enter b:"))
      Enter b:3
      >>> c = int(input("Enter c: "))
      Enter c: 4
      >>> d = (b**2) - (4*a*c)
      >>> sol1 = (-b-cmath.sqrt(d))/(2*a)
      >>> sol2 = (-b+cmath.sqrt(d))/(2*a)
      >>> print("
      ")
      >>> print(f"Results for equation, {a}x**2 + {b}x + {c} =0, are :-
      ")
      if d>0:
      print("Type of Roots : Two Distinct Real Roots")
      elif d == 0:
      print("Type of Roots : Two Equal Real Roots")
      elif d < 0:
      print("Type of Roots : Two Complex Roots")
      print(f"The solutions are {sol1} and {sol2}")

    • @SharnavTech
      @SharnavTech  2 года назад

      Connect with me on Discord (TechySharnav#1615) or Instagram (@techy_sharnav)

  • @selvaajith4384
    @selvaajith4384 3 года назад +1

    Sir, how can i decrese the power of x value? For example, input is 5*x***3 expecting output is 5*x**2

    • @SharnavTech
      @SharnavTech  3 года назад +2

      First, ** is a standard notation for exponents. Therefore, it would be 5*x**3 (equivalent to 5x³).
      Now If I got you correctly, the entire 5x³ term is an input, right?

    • @selvaajith4384
      @selvaajith4384 3 года назад +1

      @@SharnavTech Right sir...... How can i decrese the power of x in my output..... Plz help me

    • @SharnavTech
      @SharnavTech  3 года назад +1

      @@selvaajith4384 Divide the term by 5. You get x**3 term. Now take cube root of it, by raising it to power 1/3. Now Take Square of it, and multiply by 5. You get your desired output.
      Here's a small snippet to help you out:-
      gist.github.com/TechySharnav/29c9dd3235145de0496812953b4b4a06

    • @selvaajith4384
      @selvaajith4384 3 года назад +1

      @@SharnavTech thank you sooooooooooo much sir

    • @selvaajith4384
      @selvaajith4384 3 года назад +1

      @@SharnavTech hai sir...... Sorry to disturbing you..... One more doubt sir....... Same question if user give input as 5*x***3+5*x**2+5*x+5=0
      Output be like 5*x**2+5*x+5=0(decrease the x value ) but we solve it with list, array, and for loop........help me sir

  • @rishavbhattarai807
    @rishavbhattarai807 3 года назад +2

    Ohh my god
    Thanks man

  • @iqraiqraquyyum3165
    @iqraiqraquyyum3165 3 года назад +1

    You are using print(f"results for equation.....) In this line error exist please help how to remove this error and the error is based on ("") in worded comma's

    • @SharnavTech
      @SharnavTech  3 года назад

      Use triple quotes to put both single quotes and double quotes in a string.
      Example: print(f'''results ....''')

    • @utkarshrai101cartoonwala
      @utkarshrai101cartoonwala 3 года назад

      @@SharnavTech why we use f here

    • @SharnavTech
      @SharnavTech  3 года назад

      'f' here denotes that we will be formatting the string. These strings are also called F-Strings.
      The basic usage of f strings is to make string interpolation easier.

  • @emperorx5909
    @emperorx5909 4 года назад +3

    Hello, an IITian here, please don't teach students how to cheat during online test as students below 11th grade have their test online ...😇😇

    • @SharnavTech
      @SharnavTech  4 года назад +9

      Thanks for exposing the idea to everyone 🙂

    • @thunderboiii415
      @thunderboiii415 2 года назад

      Sorry it's not mandatory to tell the name of your school/college/university here, that's very lame . And, if it comes to cheating in online exams using this that's not his problem it's the problem of the schools they must keep enough maintenance so that a child can't cheat. Here is just a tutorial given for people to solve algebraic problems using python and that's a very good job don't spread hatred spread love 😇😇

    • @SharnavTech
      @SharnavTech  2 года назад

      He was joking ig..

    • @emperorx5909
      @emperorx5909 2 года назад

      @@thunderboiii415 Grow up kid, that was a joke, stop being toxic

  • @bangstar719
    @bangstar719 3 месяца назад

    is there a way to print only real values? so just to make 0*j=0

    • @SharnavTech
      @SharnavTech  3 месяца назад

      You can use the .real property to get the real part of complex number.
      For example, if X is the complex number, you can do print(X.real)

    • @bangstar719
      @bangstar719 3 месяца назад

      @@SharnavTech yeah but how can i merge that with text? like if we had print(f"The solutions are {sol1} and {sol2}"), where should we put .real? because I guess I tried all combinations but none worked.

    • @SharnavTech
      @SharnavTech  3 месяца назад

      sol1 and sol2 are variables, so you can do print(f"...{sol1.real} and {sol2.real}")

  • @yagomizuma2275
    @yagomizuma2275 2 года назад

    hello man, i have 2 questions
    1-does cmath matter? Because i used normal x1= ...d**0.5... and it works!
    2- is there a way to make this code faster? i use qpython3l to code most of the time so it would useful for me.
    appreciated

    • @SharnavTech
      @SharnavTech  2 года назад +2

      1. No, cmath doesn't really matter. You can also do **0.5
      2. Not really. The only time you can save is while entering the input. Instead of asking user to enter coefficient one by one, you can ask him to enter comma separated values.
      a,b,c = [int(i) for i in input("Enter a, b, c: ").split(",")]

  • @azranaz5989
    @azranaz5989 2 года назад +1

    please try to upload without background music, it's vert distracting. Thank you

    • @SharnavTech
      @SharnavTech  2 года назад +2

      Yes, I have changed and lowered the background music's volume in my latest videos.

    • @azranaz5989
      @azranaz5989 2 года назад +1

      @@SharnavTech thank you so much

    • @SharnavTech
      @SharnavTech  2 года назад

      No problem!

  • @LigmaBallz2137
    @LigmaBallz2137 Год назад +1

    It's 2:30 am and I got a test from IT class
    Hopefully I understand something 💀

  • @sanjadebbarma2388
    @sanjadebbarma2388 Год назад

    what is the use of this formula in softwere world i m new in computer world this is why this question came in my mind

    • @SharnavTech
      @SharnavTech  Год назад

      Well... technically it doesn't have much practical use cases. It is mostly used for personal projects.

    • @krishpal5009
      @krishpal5009 Год назад

      Actually we create a variable to define its vale in some memory..sir corret me if im wrong

  • @Shs-fx1fi
    @Shs-fx1fi 2 года назад

    Why that 0j is getting printed in the result ?

    • @SharnavTech
      @SharnavTech  2 года назад +1

      'j' denotes an imaginary part of complex number. If the solution is real, it will print 0j, which means it has no imaginary part

    • @Shs-fx1fi
      @Shs-fx1fi 2 года назад +1

      @@SharnavTech ohh ok thanks

  • @megliotwitch6693
    @megliotwitch6693 11 месяцев назад

    how do i make it so that the numbers are fractions and not decimals?

    • @SharnavTech
      @SharnavTech  11 месяцев назад +1

      Check at stackoverflow.com/q/23344185/9256189

    • @megliotwitch6693
      @megliotwitch6693 11 месяцев назад +1

      @@SharnavTech thank you

  • @dre9840
    @dre9840 3 года назад

    nice

  • @cdemr
    @cdemr 2 года назад

    File "D:\Visual Studio\Projects\quadratic formula\quadratic formula\quadratic_formula.py", line 12
    sol2 = (-b+cmath.sqrt(d)/(2*a)
    ^
    SyntaxError: invalid syntax
    Press any key to continue . . .
    is the only result I get from this program 😶 where did i f up...

    • @SharnavTech
      @SharnavTech  2 года назад

      You are missing a closing ')' bracket in the numerator.
      It should be
      sol2 = (-b+cmath.sqrt(d))/(2*a)

    • @cdemr
      @cdemr 2 года назад

      @@SharnavTech thanks, I solved it yesterday

  • @jesuisravi
    @jesuisravi 2 года назад +1

    I appreciate that you magnify the code so it is easy to read. But I hate the music.

    • @SharnavTech
      @SharnavTech  2 года назад +1

      Thanks and Sorry for that. I have changed the music now.

  • @lau-renpandoura3192
    @lau-renpandoura3192 Год назад

    I'm sure your tutorial is nice and all, but the combination of that music + the Google Translate voice made me wanna end it all

    • @SharnavTech
      @SharnavTech  Год назад

      Sorry, I had the video made in a rush...Can you give feedback on my latest videos? They have improved a lot....
      And it is not Google Translate Voice :)

  • @elgunasgarov535
    @elgunasgarov535 Год назад

    hello, cod2

    • @SharnavTech
      @SharnavTech  Год назад

      Hi (it's cod bo 2 to be precise)

  • @gill19931
    @gill19931 3 года назад

    Hello, can you solve this question
    Consider the equation Ax2 + B = 0.
     If B/A < 0, this equation has two solutions. The solutions are:
    (1) X1 = Sqrt(-B/A)
    (2) X2 = −Sqrt(-B/A)
     If B/A = 0, this equation has one solution which is X = 0
     If B/A > 0, this equation has no real number solutions
    Draw a flowchart and Write a program to have the user input any numbers for the coefficients, A and B, for this equation. If A = 0, terminate the program. Otherwise, solve the equation.

    • @SharnavTech
      @SharnavTech  3 года назад +1

      Yeah, it's pretty easy. It would require multiple if elif conditions. Based on the condition, you can calc and print the output. Make sure to include a == 0 as 1st condition, since the program has to be terminated.
      I recommend you to try on your own first. If you get stuck or need help, I am here. :)