Help with Python exercise
Solved
Blast3000
-
Phil_1857 Posted messages 1883 Registration date Status Member Last intervention -
Phil_1857 Posted messages 1883 Registration date Status Member Last intervention -
Hello,
I have an exercise to do in Python, I've done it but I'm not sure if that's really what I was supposed to do. Could you tell me if I understood the task correctly?
The question is: Write a Python program that asks the user to input a real number x and returns the value of 1/2*x (squared) + 5x - 4 and provide this algorithm in Python.
Here is what I was able to do:
Everything works well, but I wanted to know if that's what was asked of me?
EDIT: Added the LANGUAGE in the code tags (syntax highlighting).
Explanations available here:
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
Thank you for keeping this in mind in your future messages.
I have an exercise to do in Python, I've done it but I'm not sure if that's really what I was supposed to do. Could you tell me if I understood the task correctly?
The question is: Write a Python program that asks the user to input a real number x and returns the value of 1/2*x (squared) + 5x - 4 and provide this algorithm in Python.
Here is what I was able to do:
x=int(input(´´choose an integer number:´´)) x=1/2*x**2+5*x-4 print(´´the result of the calculation is:´´, x)
Everything works well, but I wanted to know if that's what was asked of me?
EDIT: Added the LANGUAGE in the code tags (syntax highlighting).
Explanations available here:
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
Thank you for keeping this in mind in your future messages.
7 answers
Hello,
to know if that’s really what is asked of me to do?
First, you are asked to enter a real number, and you write:
so you are entering an integer, not a real number...
to know if that’s really what is asked of me to do?
First, you are asked to enter a real number, and you write:
x=int(input('choose an integer:')) so you are entering an integer, not a real number...

x=float(input("choose a real number: ")) def f(x) : y=1/2*x**2+5*x-4 return y print('For x = {} , ½x²+5x-4 = {}'.format(x, f(x)))Very good!
However, you need to learn to use code tags to display your program
(see the link provided by Baladur above)
after you validate, it should look like this:
#in principle, we put the functions at the beginning... def f(x) : y=1/2*x**2+5*x-4 return y #... then the main program x=float(input("choose a real number: ")) print('For x = {} , ½x²+5x-4 = {}'.format(x, f(x)))