Reputation: 97
i am creating a txt file based on user input,But it creates files without any format, i am new to python can anyone help me..
import os
name = input("Name :")
roll = input("Roll No :")
branch = input("Branch :")
add ="name :" + name + "\n" +"Roll No :" + roll +"\n" +"Branch :"+branch
f = open(name,"a+")
m = os.path.join(name +".txt")
f.write(add)
want to get name
+
".txt" file for each user
output now is name
Upvotes: 0
Views: 71
Reputation: 393
import os
name = input("Name :")
roll = input("Roll No :")
branch = input("Branch :")
add ="name :" + name + "\n" +"Roll No :" + roll +"\n" +"Branch :"+branch
f = open(name + ".txt","a+") # This is where you are opening the file
# Below line is not contributing to the posted code at all
# m = os.path.join(name +".txt")
f.write(add)
f.close()
Upvotes: 1