לדלג לתוכן

9.1 שמות וקונבנציות תרגול

נקה אותי

  • תשכתב את הקוד הזה מחדש: שימו לב לכתוב קוד נקי
    # This is a function that does stuff
    def do_stuff(a, b):
        # Very important variable
        x = a * b
    
        # A big if statement to check stuff
        if x > 10:
            # Doing some magic here
            y = x / 2
        else:
            # Doing something else here
            y = x + 5
    
        # Returning the result
        return y
    
    
    # Another function for some reason
    def another_function():
        # Initializing some list
        list_1 = [1, 2, 3, 4, 5]
    
        # Looping through the list
        for i in list_1:
            # Printing something
            print(i)
    
        # Just because we can, let's return None
        return None
    
    
    # This function is absolutely crucial
    def foo(bar):
        # Just some arbitrary calculation
        result = bar ** 2 - 10
    
        # Uh oh, what's this?
        if result < 0:
            # We'll make it positive for some reason
            result = abs(result)
    
        # Who knows what we're doing here?
        return result
    
    
    # Entry point of the program
    if __name__ == "__main__":
        # Calling the functions in a random order
        print(do_stuff(3, 4))
        another_function()
        print(foo(5))