Learn python :Learn Python step by step
Program : Daily Routine Plane using file handling
from datetime import datetime
def getdate():
# datetime object containing current date and time
now = datetime.now()
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
return dt_string
file = int(input("Read file press 1 or entry data press 2"))
person = input("Enter the person name")
if file == 1:
RF = open(person,"r")
p= RF.read()
print(p)
else:
c = int(input("Press 1 for Food and 2 for Exercise"))
if c == 1:
meal = input("Enter the meal")
# def food(meal):
f = open(person , "a")
f.write(str(str(getdate())) + " : " + "Meal- " + meal + "\n")
else:
# def exercise(ex):
ex = input("Enter the exercise name")
f = open(person , "a")
# f.write(ex)
f.write(str(str(getdate())) + " : " + "Ex- " + ex + "\n")
Output
Read file press 1 or entry data press 21
Enter the person nameTarun
05/09/2020 00:56:44 : Roti
05/09/2020 00:59:35 : butter fly
05/09/2020 01:01:20 : Meal-Rice
Learn python :Learn Python step by step
Week | Topic | Focus |
---|---|---|
1 | Python Basics | Variables, Data Types, Input/Output |
2 | Control Structures | If/Else, Loops (for, while) |
3 | Data Structures | Lists, Tuples, Sets, Dictionaries |
4 | Functions & Modules | Defining Functions, Imports, Scope |
5 | File Handling | Reading/Writing Files |
6 | Object-Oriented Programming (OOP) | Classes, Objects, Inheritance |
7 | Exception Handling & Debugging | try/except, error messages |
8 | Final Project | Apply everything in a mini-project |
No comments:
Post a Comment