-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSurvey_Program.py
More file actions
27 lines (22 loc) · 1.04 KB
/
Survey_Program.py
File metadata and controls
27 lines (22 loc) · 1.04 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
from pathlib import Path
import csv
from colorama import init, Fore
init(autoreset=True)
def survey_questions():
question_1 = input("What types of food do you like: ").lower().replace(",", "").replace("-", "").strip()
question_2 = input("What movie genres do you like: ").lower().replace(",", "").replace("-", "").strip()
question_3 = input("What sports do you play: ").lower().replace(",", "").replace("-", "").strip()
return [question_1, question_2, question_3]
file_path = Path("Survey_Program.csv")
# If the file doesn't exist, create it with a header:
if not file_path.exists():
with open(file_path, mode="w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Food", "Movies", "Sports"])
# Get the user's input and append to CSV:
user_responses = survey_questions()
with open(file_path, mode="a", newline="") as file:
writer = csv.writer(file)
writer.writerow(user_responses)
writer.writerow([])
print(Fore.GREEN + "Your data has been saved to a CSV file!")