Exercise 66

Write an algorithm in python which asks the user to type his name, his age, his email and creates a file named personal_informations.txt containing all the information entered. Example if the information entered is: David, 37 years old, david37@gmail.com, the personal_information.txt file must contain the following information: Name: David. Age: 37 years old. Email: david37@gmail.com

Solution

import os
# let's create the file that will contain the personal informations in writ mod
fileInfo = open("personal_information.txt" , "w")
# Asking user to enter his informations
Name = input("Enter your name : ")
fileInfo.write("Name : " + Name + 'n')
Age = input("Enter your age : ")
fileInfo.write("Age : " + Age + 'n')
Email = input("Enter your email : ")
fileInfo.write("Email : " + Email + 'n')
fileInfo.close()
os.startfile("personal_information.txt")

Younes Derfoufi
my-courses.net

Leave a Reply