Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [split] Python for Everybody 5.2 assignment
largest = None
smallest = None
while True:
    num = input("Enter a number: ")
    if num == "done":
        fnum = float(num)
        print("Invalid input")
    if largest is None :
    	largest = float(num)
    elif num > largest :
        largest = float(num)
    if smallest is None :
        smallest = float(num)
    elif num < smallest :
    	smallest = float(num)
print("Maximum is",int(largest))
print("Minimum is",int(smallest))
Can someone help point to where I have gone wrong with the logic please? Thanks!
micseydel wrote Jun-14-2019, 09:01 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.

Also, I split your post from someone else's thread. Please don't hijack others' threads, create your own (you don't need to create a new thread for this question).
Can you be more specific? What inputs are you using? How exactly is the behavior different from what you want?
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
(Jun-14-2019, 04:38 PM)jonchanzw Wrote: elif num > largest :

num is a string. largest is a float. You have an fnum variable available, why not use that for comparisons?

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [split] University Assignment Help needed Nomathemba 2 298 Apr-07-2019, 11:49 PM
Last Post: micseydel
  Python Assignment 5.2 amos76823 3 1,061 Jan-17-2019, 07:34 AM
Last Post: perfringo
  Python for Everybody 3.3 assignment ramadan2099 5 1,244 Jan-09-2019, 09:10 PM
Last Post: ramadan2099
  Python for Everybody 3.1 assignment ramadan2099 14 1,615 Jan-07-2019, 07:31 PM
Last Post: ramadan2099
  [split] Python for Everybody 5.2 assignment ramadan2099 2 814 Jan-05-2019, 12:54 PM
Last Post: ramadan2099
  Python for Everybody 5.2 assignment baba04201 7 22,447 May-31-2018, 04:22 PM
Last Post: zaid03
  [split] Need help with lists to continue my assignment code cylandur 7 3,581 Oct-11-2016, 03:11 AM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)