| | |
Debug me please
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 19
Reputation:
Solved Threads: 0
Alright, this is how my newest program looks like:
and i get this error msg:
in main
in main
s = float(input('Please enter the coefficients (a,b,c): '))
ValueError: invalid literal for float(): 2, 3, -2
Help ._.
Python Syntax (Toggle Plain Text)
import math def main(): print('This program finds the real solutions to a quadratic') s = float(input('Please enter the coefficients (a,b,c): ')) a, b, c = s.split(',') discRoot = float(math.sqrt(b * b - 4 * a * c)) root1 = (-b + discRoot) / (2*a) root2 = (-b - discRoot) / (2*a) print('The solutions are:', root1, ('and'), root2) main()
and i get this error msg:
in main
in main
s = float(input('Please enter the coefficients (a,b,c): '))
ValueError: invalid literal for float(): 2, 3, -2
Help ._.
Last edited by simpatar; Oct 24th, 2009 at 9:53 am.
0
#4 Oct 24th, 2009
•
•
•
•
Correct, I use python3.
I deleted the float infront of the input since it was causing the program to bug. But shouldnt I be able to tell python to make all variables that i put in the input to be floats? if not,
how do I make them float nicely?
python Syntax (Toggle Plain Text)
>>> my_coeffs = input('Enter coefficients (a,b,c): ') Enter coefficients (a,b,c): 3, 5.5, 4.25 >>> coeff_list = my_coeffs.split(',') >>> coeff_list ['3', ' 5.5', ' 4.25'] >>> # Create an empty list to store our float values >>> float_list = [] >>> # Iterate over our string coefficients >>> for each in coeff_list: ... # turn each one into a float ... conv_coeff = float(each) ... # and finally store it ... float_list.append(conv_coeff) ... >>> float_list [3.0, 5.5, 4.25] >>>
python Syntax (Toggle Plain Text)
>>> my_coeffs = raw_input('Enter coefficients (a,b,c): ') Enter coefficients (a,b,c): 2, 4.5, 5.25 >>> float_list = [float(each) for each in my_coeffs.split(',')] >>> float_list [2.0, 4.5, 5.25] >>>
Here's the documentation about it
0
#5 Oct 24th, 2009
Just modify your code, also take care of negative numbers in your square root ...
python Syntax (Toggle Plain Text)
import math def main(): print('This program finds the real solutions to a quadratic') print() s = input('Please enter the coefficients (a,b,c): ') a, b, c = s.split(',') a = float(a) b = float(b) c = float(c) disc = b * b - 4 * a * c if disc < 0: print("root will give imaginary number") return discRoot = math.sqrt(disc) root1 = (-b + discRoot) / (2*a) root2 = (-b - discRoot) / (2*a) print() print('The solutions are:', root1, ('and'), root2) main()
May 'the Google' be with you!
![]() |
Similar Threads
- Outlook giving a debug error (Windows Software)
- How do i debug this app? (Java)
- "Run time error, do you wish to debug?" (Web Browsers)
- cannot debug ASP (ASP)
- Need to debug (Web Browsers)
- Windows 2000 Debug file (Windows NT / 2000 / XP)
- Debug message (Web Browsers)
Other Threads in the Python Forum
- Previous Thread: Running into troubles with web applications. Please help.
- Next Thread: Python module with CGI
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm assignment avogadro beginner bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float format ftp function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop module mouse number numbers output parsing path port prime program programming projects push py2exe pygame pyglet pyqt python random recursion recursive schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo verify vigenere webservice wikipedia windows wxpython xlib






