-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadoption_pet.py
More file actions
61 lines (46 loc) · 1.81 KB
/
Copy pathadoption_pet.py
File metadata and controls
61 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
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
61
'''
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)