Python Forum
help me simple code result min and max number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help me simple code result min and max number
#2
The main problem with the code is that it doesn't compare numbers. It compares number strings. It doesn't use "val" anywhere.

You can verify by doing this:
> python test.py
enter a num 5
setting largest to  5
largest:  5
***********
setting smallest to  5
smallest:  5
***********
enter a num 1234567
setting smallest to  1234567
smallest:  1234567
***********
Numerically 1234567 is greater than 5, but as a string, "5" > "1", so "5" > "1234567".

Since you are comparing strings, this makes perfect sense and is True (ord("b") > ord("7")).
if "7" is None || "bob" > "7":
If you compare "bob" and the number 7 you get a TypeError.
Reply


Messages In This Thread
RE: help me simple code result min and max number - by deanhystad - Nov-12-2022, 07:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 447 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 571 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Simple encoding code ebolisa 3 1,546 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  Can a program execute code in iPython shell and get result? deanhystad 3 1,827 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 1,599 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,878 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Simple code question about lambda and tuples JasPyt 7 3,492 Oct-04-2021, 05:18 PM
Last Post: snippsat
  My simple code don't works !! Nabi666 1 1,654 Sep-06-2021, 12:10 PM
Last Post: jefsummers
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 2,958 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea
  Plotting sum of data files using simple code Laplace12 3 3,177 Jun-16-2021, 02:06 PM
Last Post: BashBedlam

Forum Jump:

User Panel Messages

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