| | |
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
address anydbm app beginner cipher code conversion coordinates corners curves development dictionary dynamic events examples excel feet file float font format ftp function generator getvalue gui handling homework images import input ip java keycontrol line linux list lists loan loop maintain maze microcontroller millimeter mouse mysqldb number numbers output parsing path permissions port prime programming projects py2exe pygame pymailer pyqt python queue random rational raw_input recursion recursive scrolledtext searchingfile shebang slicenotation split ssh string strings table terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 variable variables vigenere web windows wx.wizard wxpython xlwt






