Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lovemycodesnippets/3ab46ecca8d9c8d9022ddbbdf28d2a1e to your computer and use it in GitHub Desktop.
Save lovemycodesnippets/3ab46ecca8d9c8d9022ddbbdf28d2a1e to your computer and use it in GitHub Desktop.
import csv
def get_user_input():
# Prompting for user input
age = int(input("Enter your age: "))
height = float(input("Enter your height (in meters): "))
weight = float(input("Enter your weight (in kilograms): "))
gender_expression = input("Please enter your gender expression: ")
return age, height, weight, gender_expression
def append_to_file(data):
# File name
file_name = 'user_data.csv'
# Writing data to CSV file
with open(file_name, mode='a', newline='') as file:
writer = csv.writer(file)
if file.tell() == 0: # Check if the file is empty (first write)
writer.writerow(['Age', 'Height', 'Weight', 'Gender Expression'])
# Writing user data
writer.write(data)
def main():
age, height, weight, gender_expression = get_user_input()
# Creating a list with input data
user_data = [age, height, weight, gender_expression]
append_to_file(user_data)
print("Data successfully appended to file.")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment