Created
March 20, 2023 15:12
-
-
Save Sachin-crypto/e0eef715640b44f8853f3af628e718ee to your computer and use it in GitHub Desktop.
A simple python program to adopt a pet and the details will be entered in a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A Python program to adopt a pet and appending the details in a file. | |
The entry can also be viewed by reading the file | |
''' | |
import datetime | |
# Defining main function | |
def get_pet(pet): | |
# If user input 1 then this condition executes | |
if pet == 1: | |
adopt = int(input("Press 1 for Pet Dog 2 for Pet Cat: \n")) | |
if adopt == 1: | |
with open("Pet-Dog.txt", "a") as f: | |
f.write(str(datetime.datetime.now()) + ": " + f"{name_inp} just adopted a Dog. \n") | |
print("Successfully Entered.") | |
elif adopt == 2: | |
with open("Pet-Cat.txt", "a") as f: | |
f.write(str(datetime.datetime.now()) + ": " + f"{name_inp} just adopted a Cat. \n") | |
print("Successfully Entered.") | |
else: | |
print("We have only CATS and DOGS.") | |
# If usr input 2 then this condition executes | |
elif pet == 2: | |
info = int(input("Enter 1 for Pet Dog Details 2 for Pet Cat Details: \n")) | |
if info == 1: | |
with open("Pet-Dog.txt") as f: | |
for content in f: | |
print(content, end='') | |
elif info == 2: | |
with open("Pet-Cat.txt") as f: | |
for content in f: | |
print(content, end='') | |
else: | |
print("Enter Valid Option!!") | |
else: | |
print("Choose 1 for adoption and 2 for Information...") | |
if __name__ == '__main__': | |
print("------------ Welcome to Pet Adoption Center -----------") | |
# Username Input | |
name_inp = input("Enter your name: \n") | |
# Taking Input from users | |
user_input = int(input("Press 1 for Adoption 2 for Information: \n")) | |
# Conditions according to user input | |
if user_input == 1: | |
get_pet(user_input) | |
else: | |
get_pet(user_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment