MrDevKnown

SELECT * FROM world WHERE humanity IS NOT NULL;

  • Home
  • About
  • Contact Us

Hello there! In this article we are going to create a programmer way to write an application. We will write an application using Python.



Ideation

So, as you all know that we have a specific format to write an application. In this post, I've chosen a leave application. Firstly, what we want is the sample of the application. Then, we are going to format the sample of the application with the important information. And at the end, we'll create a new file to output the text application and save it.


Prerequisites

A basic knowledge of file handling and string formatting.

The way I am going to make the program is using file handling in Python with string formatting. But you can also just make the use of string formatting to modify the program.


How?

Firstly I saved a very raw and simple sample of application written in a file named, "letter.txt". I've used a simple format. Modify the file as per your requirements.

To

the Principal

{school_name}


Subject: Sick Leave Application


I am {name} of {class_name} of your institute. I am writing this application to inform you that I am suffering from {reason} and therefore, I want sick leave from school. I got this infection last night and I will not be capable to come to the office for from {start_date} for a several days. As advised by my doctor, I should take rest and recover appropriately before continuing work. The report from the doctor is also attached for your reference.


Kindly grant me a leave for {no_days} days.


Yours Sincerely,

{name}


Note: Just keep the data that is to be changed with the application inside "{ }" brackets. And use a single unique word to define the information used inside it. We are going to change this information using string formatting


Now create a Python script file, say "letter.py" and start to code.


Coding

Firstly, we are using the template saved in our file, "letter.txt". So, we'll have to use it, open and read the content inside it. We are going to use the concept of file handling here.

letter = open("letter.txt", "r")
text = letter.read()

In these two lines, I've opened the file, in read mode (because we don't want to modify the file) and then I've read the content inside the file using read function and stored it in a variable, text.

Now, we have got the format in the text variable. Now, just replace those reference variables written inside the "{ }" brackets with the required data.

We're going to make the user input the required data. So, let's make some variables to let the user input some data.

name = str(input("Enter your name: "))
school_name = str(input("Enter your school's name: "))
class_name = str(input("Enter the class: "))
reason = str(input("Enter the reason for being absent: "))
start_date = str(input("Enter the date from which leave starts: "))
end_date = str(input("Enter the date from which leave ends: "))
no_days = str(input("Enter the no. of days: "))

Note: I've used the same word references stored in the file inside "{ }" brackets. You can also do the same to remove any confusion.

Now, everything is well setup for us.

At last, We have to change the content in the text variable.

temp_str = f"{text}".format(name=name, school_name=school_name,
class_name=class_name, reason=reason, start_date=start_date,
end_date=end_date, no_days=no_days)

I've created a variable and then changed its content with the text content of text variable, using string formatting. And after that in the same variable I've replaced the references with the variables.

This is a bit complicated to see as I've combined two steps in one. But, just look at it once and you will get it easily. If not, separate the two steps and print them one by one and see the difference.

At the end, close the opened file, "letter.txt".

letter.close()

Now, you have created your application using python. Print the "temp_str" variable and see the output.

Here, we are going to make a new output file to save the application.

So, we'll again use the concept of file handling.

output = open("output.txt", "w")

output.write(temp_str)

output.close()


Congratulations! You have created a Python program to create your own application.


Code:

print("""



         ___         ___   ___            ___
|    |  |     |     |     |   |  |\\  /|  |
|    |  |__   |     |     |   |  | \\/ |  |__
| /\\ |  |     |     |     |   |  |    |  |
|/  \\|  |___  |___  |___  |___|  |    |  |___



""")


letter = open("letter.txt", "r")


text = letter.read()


name = str(input("Enter your name: "))
school_name = str(input("Enter your school's name: "))
class_name = str(input("Enter the class: "))
reason = str(input("Enter the reason for being absent: "))
start_date = str(input("Enter the date from which leave starts: "))
end_date = str(input("Enter the date from which leave ends: "))
no_days = str(input("Enter the no. of days: "))


temp_str = f"{text}".format(name=name, school_name=school_name,
class_name=class_name, reason=reason, start_date=start_date,
end_date=end_date, no_days=no_days)


letter.close()


# print(temp_str)


output = open("output.txt", "w")


output.write(temp_str)


output.close()



Newer Posts Older Posts Home

ABOUT ME

Web developer, designer. A self taught programmer. Don't hesitate to come for say a small "hello!"
Shivesh Tiwari

POPULAR POSTS

  • How to create a shining / glowing effect around the cursor on mouse hover over a div? Glassmorphism Tutorial
  • Javascript code to display a welcome message after accepting the name of the user using a prompt box
  • How to make Windows 11 Website Design | Adding Working App Windows | Dark Mode and other things
  • How to test your typing speed with Python - Make a Python app
  • Make a Windows 11 themed Website - HTML, CSS Windows 11 design
  • Top must have windows software for a developer
  • Qt Designer UI to python file export
  • Python PyQt5 complete Setup Windows
  • PyQt5 draggable Custom window code
  • Make your own Python IDE + Text Editor (Pykachu)

Categories

  • best javascript project 12
  • code 5
  • dino game 1
  • dislike 1
  • easy python projects 9
  • flask 1
  • free python code 10
  • game 2
  • git 1
  • github 1
  • hack 2
  • hack chrome dino game 1
  • hack game 1
  • html best website 4
  • javascript website 6
  • learn javascript 9
  • learn programming 13
  • learn python 15
  • like 1
  • like dislike system php 1
  • mrdevknown 5
  • music player 1
  • notification 1
  • php 2
  • programming 9
  • project 9
  • pyqt5 4
  • python 16
  • python IDE 2
  • python projects 8
  • React 5
  • react js 6
  • software 5
  • Tkinter 2
  • web app 4
  • website 4
Powered by Blogger
MrDevKnown

Search This Blog

Archive

  • August 20231
  • March 20231
  • December 20221
  • September 20222
  • August 20221
  • June 20221
  • March 20221
  • January 20226
  • December 20211
  • November 20213
  • October 202111
  • September 20213
  • August 20213
Show more Show less
  • Home
  • About
  • Contact Us

Subscribe

Posts
Atom
Posts
All Comments
Atom
All Comments

Subscribe

Posts
Atom
Posts
All Comments
Atom
All Comments

Categories

  • React5
  • Tkinter2
  • best javascript project12
  • code5
  • dino game1
  • dislike1
  • easy python projects9
  • flask1
  • free python code10
  • game2
  • git1
  • github1
  • hack2
  • hack chrome dino game1
  • hack game1
  • html best website4
  • javascript website6
  • learn javascript9
  • learn programming13
  • learn python15
  • like1
  • like dislike system php1
  • mrdevknown5
  • music player1
  • notification1
  • php2
  • programming9
  • project9
  • pyqt54
  • python16
  • python IDE2
  • python projects8
  • react js6
  • software5
  • web app4
  • website4

Translate

Pages

  • Home
  • Privacy Policy

Popular Posts

Music Player web app made in HTML, CSS, Javascript

Music Player web app made in HTML, CSS, Javascript

August 03, 2021
Top must have windows software for a developer

Top must have windows software for a developer

September 17, 2022
Javascript code to display a welcome message after accepting the name of the user using a prompt box

Javascript code to display a welcome message after accepting the name of the user using a prompt box

August 20, 2022

Trending Articles

  • How to create a shining / glowing effect around the cursor on mouse hover over a div? Glassmorphism Tutorial
  • Javascript code to display a welcome message after accepting the name of the user using a prompt box
  • How to make Windows 11 Website Design | Adding Working App Windows | Dark Mode and other things
  • How to test your typing speed with Python - Make a Python app

Popular Posts

  • Top must have windows software for a developer
  • Javascript code to display a welcome message after accepting the name of the user using a prompt box
  • How to create a shining / glowing effect around the cursor on mouse hover over a div? Glassmorphism Tutorial

Labels

Distributed By Gooyaabi | Designed by OddThemes