hi , can you please write the code of the following program
read a text file line by line and display each word separated by a #
try to take input
hi , can you please write the code of the following program
read a text file line by line and display each word separated by a #
try to take input
Hi @shubhamkswn00
Please refer the following code :
filein = open("Mydoc.txt",'r') for line in filein: word= line .split() for w in word: print(w + '#',end ='') print() filein.close()
Hope this might helps
sir not working showing syntax error
Hi @shubhamkswn00
Please check your code once again because it’s working fine at my end
Sir but i want to take input from user which is not here
sir basically user can select the file from which he want to do the task
sir basically user can select the file from which he want to do the task please help me
Hi @shubhamkswn00
Please refer the following code :
filename = input("Enter file name along with file path : ")
filein = open(filename,‘r’)
for line in filein:word= line .split() for w in word:
print(w + '#',end ='')
print()
filein.close()
Hope this might helps
no sir i don’t want this Basically i want to take input from the user
sir but i don’t want it to be like this
sir basically i want to take input from the user
Hi @shubhamkswn00
Over here we are taking input from the user
Python provides us with two inbuilt functions to read the input from the user.
input ( ) : This function first takes the input from the user and then evaluates the expression, which means Python automatically identifies whether user entered a string or a number or list. If the input provided is not correct then either syntax error or exception is raised by python.
Hope this might clarify your doubt
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.