Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Checking my basic understanding of coding
Need a little help Rolleyes

I'm kind of new to python and trying to understand basics of python. Trying to show what I understand by looking at the following coding. Correct me if i'm wrong in here. The # comment is what I understand about each coding line written down

# Create function get_float
def get_float(pmp):
    # assigning values to ‘val’
    val = float(0.0)
    # Creating while loop
    while True:
            # converting user input to float data type
            val = float(input(pmp))
            # checking condition if val is negative
            if val < 0.0:
                print("Cannot accept negative values!")
            # Breaks us out of the loop
        # Throw error
        except ValError:
            return 0.0
    # returning current value of ‘val’
    return val

# Function to: creating function run
def go():
    # create an array called ‘rv’
    rv = RecyclingMachine()
    # assigning values to variable ‘next_customer’
    next_customer = True
    # Creating a Do-While loop
    while next_customer:
        # assign values to rv array
        # assign values to rv array
        # assign values to rv array
        # Creating a Do-While loop
        while True:
            # Getting the input in strings
            answer = get_str("(N)ext customer, or (Q)uit?")
            # Converting input into uppercase
            answer = answer.upper()
            # checking value of answer using a condition
            if answer == "N":
	       # Breaks us out of the loop
            elif answer == "Q":
                # Quite the loop
                # Display what’s inside print statement
                print("Invalid Response")

Thanks for having a look! Smile
As far as I can tell, yes. But it's not clear what RecyclingMachine is or what vm is. I some problems with the way the code is written, and I would expect an error on line 17 (although it's clear this is not the complete code, and there may be some other code that prevents that error. I expect I would have a problem with that code too).
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

The comment on line 16 isn't correct. The code isn't throwing (or "raising" in Python) an error. It's catching and handling an error that has been raised.
Line 48 doesn't break the loop, it's calling sys.exit() to end the program immediately.

Personally, I think this function should be used very very rarely, if ever. I think of it as a big red flag that something extremely bad happened, and you don't know how to proceed. Libraries should never use it, only client code (imagine if your webbrowser just crashed for some minor issue).

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python coding Nomathemba 3 185 Apr-15-2019, 09:18 PM
Last Post: Yoriz
  understanding some code souprqtpie 2 168 Apr-03-2019, 10:41 AM
Last Post: perfringo
  CODING HELP soyboypablo 1 208 Feb-22-2019, 09:45 AM
Last Post: Larz60+
  Basic Dijkstras Implementation grandpapa10 7 325 Jan-23-2019, 11:50 AM
Last Post: grandpapa10
  Need help with coding! codemaster 2 325 Dec-04-2018, 09:45 PM
Last Post: nilamo
  Basic Quiz/Game searching1 10 889 Nov-18-2018, 03:58 AM
Last Post: ichabod801
  Understanding formatting mickandralphscrier 6 469 Nov-14-2018, 06:34 PM
Last Post: j.crater
  Problem with a basic if challenge erfanakbari1 2 359 Oct-12-2018, 08:04 AM
Last Post: erfanakbari1
  new to coding abdullahali 3 501 Sep-30-2018, 01:49 PM
Last Post: gruntfutuk
  Basic program balajee 2 528 Sep-11-2018, 07:19 PM
Last Post: gruntfutuk

Forum Jump:

Users browsing this thread: 1 Guest(s)