Python Forum
Inconsistency in Python programming language?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inconsistency in Python programming language?
#17
adt Wrote:If experts in python community were to keep striving in their zeal (though well intended) to justify all that exists
You're strongly mistaking, it is my deep conviction that int('4.5') must raise an exception. It gives the program a chance to do take proper action if the string happens to contain a floating value, for example
while True:
    s = input('Please enter the page number'))
    try:
        pageno = int(s)
    except ValueError:
        print('Error: an integer is required, not', repr(s))
But if int() accepts floating value, how can I recognize a floating value to reject it? I need to test it before the conversion to int and create another way to ensure it's an integer, something like
import re
while True:
    s = input('Please enter the page number'))
    if re.match('^\s*\d+\s*$', s):
        pageno = int(s)
    else:
        print('Error: an integer is required, not', repr(s))
adt Wrote:It would seem that statements (A) & (B) are consistent with each other, while the same could not be said for statements © & (D).
Again you're mistaking about the intent of the isnumeric() method. It doesn't mean that the string represents a numeric value, it means that all the characters in the string are numeric characters. It is a different purpose.
Reply


Messages In This Thread
RE: Inconsistency in Python programming language? - by Gribouillis - Oct-05-2019, 02:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Programming robots using Python OscarBoots 5 4,941 Oct-31-2021, 09:38 AM
Last Post: Larz60+
  logo language code into python aayushi98 2 85,089 Jan-26-2021, 09:02 PM
Last Post: Serafim
  Programming Difficult math in Python Huntern 6 7,094 Oct-17-2019, 06:32 AM
Last Post: Huntern
  Terms describing Python Programming language leodavinci1990 3 3,924 Aug-12-2019, 02:48 PM
Last Post: leodavinci1990
  Please help a newbie choose which programming language to learn. yeto 2 4,442 Feb-25-2019, 12:56 AM
Last Post: yeto
  Python Programming Projects for Beginners jack_sparrow007 3 4,463 Dec-26-2018, 07:52 PM
Last Post: micseydel
  How to get image from WolframAlpha by using Python language manhnt 1 3,388 Oct-27-2018, 02:07 PM
Last Post: Larz60+
  Programming Python as a MS Windows app? Brian123 8 6,152 Oct-17-2018, 10:26 PM
Last Post: Brian123
  Help with Python programming mediaos 5 5,081 Aug-08-2018, 01:02 PM
Last Post: Larz60+
  How to make the python default language be 3.6 instead of 2.7 sylas 4 8,073 Jul-06-2018, 06:11 AM
Last Post: sylas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020