Python Forum
I want to check for the smallest value entered by the user
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want to check for the smallest value entered by the user
#1
Below is my code. Instead of getting the smallest value entered by user, i get the last inputted value. I am a beginner so taking baby steps to lean python. Any leads is appreciated. Thanks
largest=None
smallest=None
while True:
    num=input("enter a number")
    if num == 'done':
        break
    try:
         val=int(num)
    except:
        Print("error")
    continue
    if smallest is None:
    smallest=val
    elif:
    val<smallest
    smallest=val
Print("smallest", val)
Reply
#2
You are printing out "val" when you meant to print out "smallest", that is why it is returning the most recent number.
Reply
#3
As provided your code won´t run as there are a lot of bugs.
Indentation is sometimes wrong and print() is written with lower p and not capital P
elif: won´t work either
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Try,Except,Else to check that user has entered either y or n (Code block pasted) RandomNameGenerator 3 2,324 Jun-29-2021, 08:21 PM
Last Post: RandomNameGenerator
  Please help me to ask to enter again itself when value entered is not a number. sunil422 5 2,603 Aug-13-2020, 02:15 PM
Last Post: perfringo
  How to reuse positional arguments entered in terminal. rcmanu95 1 1,865 Jul-04-2020, 01:00 AM
Last Post: bowlofred
  how to divide one big equation entered as a string to small chunks gungurbuz 1 1,610 May-28-2020, 03:46 PM
Last Post: Larz60+
  Sorting numbers from smallest to biggest Dokugan 2 2,210 Apr-14-2020, 09:24 PM
Last Post: Larz60+
  smallest Cosine distance in Graph vino689 3 2,304 Jan-12-2020, 08:06 AM
Last Post: rmspacedashrf
  How to check if user entered string or integer or float?? prateek3 5 11,322 Dec-21-2019, 06:24 PM
Last Post: DreamingInsanity
  Saving entered text for next usement Rigunas 1 2,331 Dec-21-2018, 10:00 AM
Last Post: buran
  How do I calculate the smallest value that is recognized as a difference when compari AFoeee 1 2,775 Oct-28-2018, 10:48 PM
Last Post: Gribouillis
  Is there any way to check if a function is user-defined? dullboy 11 10,320 Oct-06-2016, 03:42 AM
Last Post: dullboy

Forum Jump:

User Panel Messages

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