Posts: 232
Threads: 2
Joined: Sep 2017
(Sep-12-2018, 11:19 PM)JHPythonLearner Wrote: Hi gontajones. Thank you for your reply.
Listen, I am new to Python. I have taken a couple of online courses that lasted a few hours each. Now I need to code.
Having said that, this is what I have done:
input("Enter a number")
user_answer = input("Enter a number")
user_answer_squared = user_answer**2
print(user_answer_squared)
In Python 3.x (which I hope you are using) ALL input is a string. That is, a series of unicode characters that Python does not treat as a numeric value.
You need to tell Python to
cast a string to the kind of number you want. IF the string is not valid as a number, an exception will be raised and your programme will halt with an error message.
num = int(user_answer)
will attempt to convert the string referenced by user_answer into an integer referenced by num which you can then use in your subsequent code.
You can use
float()
to cast to a floating point number.
I am trying to help you, really, even if it doesn't always seem that way