#πŸ”’ Beginners Errors

14 messages Β· Page 1 of 1 (latest)

spare mantle
#

I wanted to develop a quiz system (I am a complete beginner), which would check if the entered value is float or anything else. It is not working. Here is the code:-
a = input("Enter a float(nothing else): ")

now, I will store the type of a in another variable, i.e., b

b = type(a)
if(type(a) == float):
print("You answered correctly!")
else:
print("You could not do it correctly!")
print(f"The type of your input is {b}")

amber tangleBOT
#

@spare mantle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

delicate fog
#

remember that digits can still be str

#

123.456 vs. "123.456"

spare mantle
#

Is there any way to make such a code as I had said before?

gleaming snow
delicate fog
#

Yes exactly, if you want to verify that what the user enters works as a valid float, it's common to just use try/except

#

we basically attempt to convert to float and see if that would have caused an error

spare mantle
#

Okay. Thanks for the quick help!

gleaming snow
#

can't really think of another way to check for float without except πŸ€·β€β™‚οΈ

spare mantle
#

!close

amber tangleBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.