Python Forum
Checking my basic understanding of coding
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking my basic understanding of coding
#1
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:
        try:
            # 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!")
                continue
            # Breaks us out of the loop
            break
        # 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
        vm.accept_product()
        # assign values to rv array
        vm.identify_product()
        # assign values to rv array
        vm.print_receipt()
        # 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
                break
            elif answer == "Q":
                # Quite the loop
                exit()
            else:
                # Display what’s inside print statement
                print("Invalid Response")
Thanks for having a look! Smile
Reply


Messages In This Thread
Checking my basic understanding of coding - by dilans94 - Jan-07-2019, 11:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I need help on a basic coding question Presssure 1 4,156 May-23-2018, 05:12 AM
Last Post: micseydel
  Basic Coding Slays College Girl AnjyilLee 5 4,676 Sep-15-2017, 01:19 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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