Intriguing Python Code

In the late 1980s, Python’s history is about to publish. Python has succeeded the ABC Programming Language, which had interfaced with the Amoeba Operating System and had the feature of exception handling. The inventor Guido van Rossum began doing his application-based work in December 1989 in Netherland. First, he started the project as a hobby because he wanted to keep himself occupied during Christmas. He had already helped to create ABC earlier in his career, and he had seen some issues with ABC but liked most of its features. After that, what he did was brilliant. He took the syntax of ABC and some of its components.

https://visualwebz.com/python/

There were a lot of complaints, too. He fixed those issues thoroughly and had created a good scripting language that had removed all the weaknesses. It released the language in 1991. The inspiration for the name Python came from a British television show named “Monty Python’s Flying Circus” because he idolized the show. He wanted a short, rare, and slightly baffling name for his invention, and hence he named it Python! He was a very benevolent dictator until he stepped down from the position on July 12, 2018. He used to work for Google but currently working at Dropbox.

It used fewer codes to express the concepts compared to Java, C++ & C. Its design philosophy was quite good. Its primary aim is to provide code readability and advanced developer productivity. It had more than sufficient proficiency to provide classes inheritance, several data type exception handling, and functions. Python is a language for any developer to grasp with simplicity, ease of use, and versatility. The flexibility of this language allows you to explore any option you want to add, and many excellent resources will assist you in achieving the task with greater ease. It is a fantastic idea to start working on numerous Python projects as you develop more skills in the real world.

When learning a programming language, for example, using Python, it does not always have a positive benefit but also a drawback. It is good to know its strengths and weaknesses to use it. First, let’s dive into its advantage. It is effortless to read, learn, and write. Something highly used is an English-like syntax that does reading and understanding the coding easier. It is easy for people to pick up and learn. That is why its beginner should know it. It has fewer lines of code compared to Java and C/C++. It improved productivity because of its simplicity. The developers can focus on solving the problem that they do not spend too much time on it. You write less code means they completed more things. Python is an interpreted language, which means Python executes the code line by line. In case of an error, it will report the error that occurred. Python shows the one error even with multiple errors that make debugging easier.

Python does not know the type of variable until running the code. It will naturally assign the data type during execution. The programmer does not need to worry about declaring variables and data types. What is a good thing with Python is the free source it offers. Python comes under OSI approved open-source license. It makes it easier to use and circulate. You can download the source code, change it, and even distribute your version of the code. This is useful for organizations that want to change specific behavior and use their version for development. The standard library of Python is vast.

All the functions you need can easily find in the library. You do not have to rely on external libraries. Still, even if you do, a Python package manager (pip) makes things easier to import other significant loads from the Python package index. It comprises over 200,000 packages. In many languages like C/C++, you need to change your code to run the program on different platforms. That is not the same with Python. You can write once and run it anywhere but be careful not to depend on the system feature of the code.

As you heard about advantages, you also should learn about its disadvantages. Python is an interpreted language and dynamically typed language. Line by line can sometimes lead to slow execution. The dynamic nature handles the slow speed of Python because it must do extra load to execute the code, so using Python when speed is necessary to finish the task at hand. The simplicity is good, but there is a minor tradeoff. Python uses a large amount of memory that can be a disadvantage while building applications when memory is necessary. The Python weakness of mobile computing.

We use Python in server-side programming. We do not see it as a client-side on the mobile applications because it is not memory efficient and has slow processing power compared to other languages. The database for Python is easy and stress-free access, but when we are interacting with a database, it is lack behind. The data access is primitive compared to popular technologies. Enterprises need a smooth interaction that is not Python. Runtime Errors are an issue in Python. As we know, Python is a dynamically typed language, so the data type of variable can change anytime. A variable containing an integer number may influence the string in the future, which can point to Runtime Errors. Python programmers need to perform complete testing of any applications.

Today, many financial institutions, technology companies, government agencies, and more look for candidates who mastered Python for roles within the web, software development, data science, and others. Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify, and several other massive companies use Python. It’s one of the four major languages at Google, while Google’s YouTube uses Python. Same with Reddit, Pinterest, and Instagram. They also wrote the original BitTorrent client in Python. They used Python as a scripting language to supervise Maya, a standard 3D modeling and animation tool. They use heavy Python in academic research, particularly bioinformatics, biology, and mathematics. It is the standard language that university computer science programs teach beginners.

Mad Libs Generator

It is the best hands-on experience for a student, just starting with software development. Primarily it focused on strings, variables, and concatenation. It is a project that will teach you how to manipulate user-inputted data. The program asks the user to enter a series of inputs in Mad lib. The information can be anything from adjective, noun, pronoun, or anything the user enters. Once all the inputs are listed, the application will take the data and arrange the information into a story template form.

Source Code:

“”” Mad Libs Generator
— — — — — — — — — — — — — — — — — — — —
“””
//Loop back to this point once code finishes
loop = 1
while (loop < 10):
// All the questions that the program asks the user
noun = input(“Choose a noun: “)
p_noun = input(“Choose a plural noun: “)
noun2 = input(“Choose a noun: “)
place = input(“Name a place: “)
adjective = input(“Choose an adjective (Describing word): “)
noun3 = input(“Choose a noun: “)
// Displays the story based on the users input
print (“ — — — — — — — — — — — — — — — — — — — — — “)
print (“Be kind to your”,noun,”- footed”, p_noun)
print (“For a duck may be somebody’s”, noun2,”,”)
print (“Be kind to your”,p_noun,”in”,place)
print (“Where the weather is always”,adjective,”.”)
print ()
print (“You may think that is this the”,noun3,”,”)
print (“Well it is.”)
print (“ — — — — — — — — — — — — — — — — — — — — — “)
// Loop back to “loop = 1”
loop = loop + 1

Number Guessing

This project is an exciting game for beginners to make. This program generates a number from 1 to 10, 1 to 100, or any specified range. The user must guess the number after the clue given by the computer. Every time users answer is incorrect. It will provide more clues to make it easier for them to correct the number but at the cost of reducing the score. The hints can be a multiplied number, be divisible, less than or greater than, or a combination.

The program also requires functions to check if an actual number you entered by the user or not. It compares the input number with a certain number to find the difference between them.

Source code:

import randomimport math# Taking Inputslower = int(input(“Enter Lower bound:- “))# Taking Inputsupper = int(input(“Enter Upper bound:- “))# generating random number between# the lower and upperx = random.randint(lower, upper)print(“\n\tYou’ve only “,round(math.log(upper — lower + 1, 2)),“ chances to guess the integer!\n”)# Initializing the number of guesses.count = 0# for calculation of minimum number of# guesses depends upon rangewhile count < math.log(upper — lower + 1, 2):count += 1# taking guessing number as inputguess = int(input(“Guess a number:- “))# Condition testingif x == guess:print(“Congratulations you did it in “,count, “ try”)# Once guessed, loop will breakbreakelif x > guess:print(“You guessed too small!”)elif x < guess:print(“You Guessed too high!”)# If Guessing is more than required guesses,# shows this output.if count >= math.log(upper — lower + 1, 2):print(“\nThe number is %d” % x)print(“\tBetter Luck Next time!”)# Better to use This source Code on pycharm!

Python Fake Information Generator

You can download the Faker python program that you can install using the pip in the terminal. This program creates fake data like name, email, or profile information about a person. Each time you run this coding, it will generate random data. There is numerous fascinating method that you can use such, as fake text, credit card, and many more to choose from using the Faker syntax.

Source Code:

# initialize a generatorfake = Faker()#create some fake dataprint(fake.name())print(fake.date_between(start_date='-30y', end_date='today'))print(fake.color_name())

Reminder Alert

It is good to have a reminder to remind us of what we have to do for today or if we forgot what we need to accomplish for that day. With the help of Python, it is easy for us to automate a task that would be complex for human beings. You can accomplish this with the help of appropriate libraries and coding patterns that apply to the assignment. This project will help us notify our task daily accordingly. To complete this task, you will use the library and player that you can install using the pip command, which you used to specify the notification request accordingly.

Source code:

import timefrom plyer import notificationif __name__ == "__main__":while True:notification.notify(title = "ALERT!!!",message = "Take a break! It has been an hour!",timeout = 10)time.sleep(3600)

Alarm Clock

The alarm clock has been around for many generations now. Even as technology advances, the clock is essential for many people. People around the world use it. However, this project is not the simple alarm clock that you can make. It is quite a simple Command Line Interface (CLI) Python application. You can put the YouTube links in a text file and design the application to read the file.

Source code:

# Import Required Libraryfrom tkinter import *import datetimeimport timeimport winsoundfrom threading import *# Create Objectroot = Tk()# Set geometryroot.geometry(“400x200”)# Use Threadingdef Threading():t1=Thread(target=alarm)t1.start()def alarm():# Infinite Loopwhile True:# Set Alarmset_alarm_time = f”{hour.get()}:{minute.get()}:{second.get()}”# Wait for one secondstime.sleep(1)# Get current timecurrent_time = datetime.datetime.now().strftime(“%H:%M:%S”)print(current_time,set_alarm_time)# Check whether set alarm is equal to current time or notif current_time == set_alarm_time:print(“Time to Wake up”)# Playing soundwinsound.PlaySound(“sound.wav”,winsound.SND_ASYNC)# Add Labels, Frame, Button, OptionmenusLabel(root,text=”Alarm Clock”,font=(“Helvetica 20 bold”),fg=”red”).pack(pady=10)Label(root,text=”Set Time”,font=(“Helvetica 15 bold”)).pack()frame = Frame(root)frame.pack()hour = StringVar(root)hours = (‘00’, ‘01’, ‘02’, ‘03’, ‘04’, ‘05’, ‘06’, ‘07’,‘08’, ‘09’, ‘10’, ‘11’, ‘12’, ‘13’, ‘14’, ‘15’,‘16’, ‘17’, ‘18’, ‘19’, ‘20’, ‘21’, ‘22’, ‘23’, ‘24’)hour.set(hours[0])hrs = OptionMenu(frame, hour, *hours)hrs.pack(side=LEFT)minute = StringVar(root)minutes = (‘00’, ‘01’, ‘02’, ‘03’, ‘04’, ‘05’, ‘06’, ‘07’,‘08’, ‘09’, ‘10’, ‘11’, ‘12’, ‘13’, ‘14’, ‘15’,‘16’, ‘17’, ‘18’, ‘19’, ‘20’, ‘21’, ‘22’, ‘23’,‘24’, ‘25’, ‘26’, ‘27’, ‘28’, ‘29’, ‘30’, ‘31’,‘32’, ‘33’, ‘34’, ‘35’, ‘36’, ‘37’, ‘38’, ‘39’,‘40’, ‘41’, ‘42’, ‘43’, ‘44’, ‘45’, ‘46’, ‘47’,‘48’, ‘49’, ‘50’, ‘51’, ‘52’, ‘53’, ‘54’, ‘55’,‘56’, ‘57’, ‘58’, ‘59’, ‘60’)minute.set(minutes[0])mins = OptionMenu(frame, minute, *minutes)mins.pack(side=LEFT)second = StringVar(root)seconds = (‘00’, ‘01’, ‘02’, ‘03’, ‘04’, ‘05’, ‘06’, ‘07’,‘08’, ‘09’, ‘10’, ‘11’, ‘12’, ‘13’, ‘14’, ‘15’,‘16’, ‘17’, ‘18’, ‘19’, ‘20’, ‘21’, ‘22’, ‘23’,‘24’, ‘25’, ‘26’, ‘27’, ‘28’, ‘29’, ‘30’, ‘31’,‘32’, ‘33’, ‘34’, ‘35’, ‘36’, ‘37’, ‘38’, ‘39’,‘40’, ‘41’, ‘42’, ‘43’, ‘44’, ‘45’, ‘46’, ‘47’,‘48’, ‘49’, ‘50’, ‘51’, ‘52’, ‘53’, ‘54’, ‘55’,‘56’, ‘57’, ‘58’, ‘59’, ‘60’)second.set(seconds[0])secs = OptionMenu(frame, second, *seconds)secs.pack(side=LEFT)Button(root,text=”Set Alarm”,font=(“Helvetica 15”),command=Threading).pack(pady=20)# Execute Tkinterroot.mainloop()

Python Website Blocker

. We like surfing on the internet, by t sometimes so many unwanted websites keep showing up. Everyone experiences a pop-up on a website they visit. It is one of the python projects where you can build a program that blocks certain websites from opening. This program is valuable for students who want to study without online distractions. Creating Python projects can boost your resume and much fascinating for others to see.

Source code:

# Run this script as rootimport timefrom datetime import datetime as dt# change hosts path according to your OShosts_path = "/etc/hosts"# localhost's IPredirect = "127.0.0.1"# websites That you want to blockwebsite_list =["www.facebook.com","facebook.com","dub119.mail.live.com","www.dub119.mail.live.com","www.gmail.com","gmail.com"]while True:# time of your workif dt(dt.now().year, dt.now().month, dt.now().day,8)< dt.now() < dt(dt.now().year, dt.now().month, dt.now().day,16):print("Working hours...")with open(hosts_path, 'r+') as file:content = file.read()for website in website_list:if website in content:passelse:# mapping hostnames to your localhost IP addressfile.write(redirect + " " + website + "\n")else:with open(hosts_path, 'r+') as file:content=file.readlines()file.seek(0)for line in content:if not any(website in line for website in website_list):file.write(line)# removing hostnmes from host filefile.truncate()print("Fun hours...")time.sleep(5)

The simplicity of Python allows the developer to create a spectacular project. The tools are helpful in Python. Anyone can build almost any project. You can construct any AI, Data science, computer vision, or natural language that you want to thank for the versatility of this programming language.

In this article, we discussed amusing codes to learn. It includes Mad Lib Generator, number guessing, fake information generator, reminder alert, alarm clock, and website blocker. With the code, various references, and other resources, you can build these projects without too much difficulty.

Creating many projects can help you learn more about Python. After working on these projects, take up some of your own choices and start exploring and experimenting with other options as well. It would be best to stop learning because there is always something new to discover every day.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store