Python Forum
Do you keep up with Python Exercises?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do you keep up with Python Exercises?
#1
I am not sure if this is the right place to put this but I thought it would be helpful for some people.

I have been doing python exercises / sample problems for a few weeks now and I find that they are very helpful in a lot of ways. I will provide an example of one in this thread to those of you who are unfamiliar. Of course, they aren't too hard to find, all you have to do is type in "Python Exercises" into google and it will lead you straight into a dictionary full of pages that contain them. I just thought maybe it would be good to recommend to others. Regardless of your skill-set or background, you may come across something that you have never seen before and not only that, you may even solve something that used to frustrate you.

Here is a very basic example: (Credits to PyNative for providing the sample problem)

Quote:Question 5: Get a list of numbers from the user. Return True if first and last index value in the given list are the same. If not, return False!

Since I am getting better, I like to utilize areass of python that I am learning to make sure I have them understood. Like so,

import time
alist = []

def compare():
    if alist[0] == alist[4]:
        print("\nNumber List:", alist, "<- Comparing Index (First and Last): They are the same!")
        print("Program Finished!")
        time.sleep(10)
        exit()

    else:
        print("\nNumber List:", alist, "<- Comparing Index (First and Last): They are not the same!")
        print("Program Finished!")
        time.sleep(10)
        exit()
def create_list():
    try:
        var = input("[Please enter a number into the list]: ")

        if var.isalpha():
            raise TypeError

        elif var.isdigit():
            if len(alist) > 3:
                print(f"\nValue entered correctly. Now adding {var} to our number list.\n")
                alist.append(var)
                print("Our current list: ", alist)
                print("[Finished creating the list. Let's move on to our calculations!]")
                print("-----------------------------------------------------------------------------")
                compare()
                
            print(f"\nValue entered correctly. Now adding {var} to our number list.\n")
            alist.append(var)
            print("Our current list: ", alist)
            create_list()

        else:
            raise TypeError

    except TypeError:
        print("\n[TypeError]: Invalid Entry| Please enter a numerical value only.\n")
        create_list()

print("[Welcome to List Builder v1.0]".center(125), "Let's Compare Index Values!".center(159), "\n\n")
create_list()
You can always solve them in your own way. You can do it more complex, less complex. The end-goal really is to produce the desired outcome. Ultimately if you can do that while following common practice and improve yourself as a programmer along the way, great!

This is what I am currently doing, alongside joining a coding forum to help me increase my knowledge amongst the languages I work in.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Drills/Exercises for collections, itertools, and common built-in data structures? Cranberry 2 3,307 Apr-26-2018, 05:43 PM
Last Post: Cranberry
  Helpful exercises NikonNorm 4 3,327 Apr-18-2018, 01:47 PM
Last Post: vaison

Forum Jump:

User Panel Messages

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