Sunday 15 June 2014

Python (latest version) Syntax Error -


I have written this sample program which means to open a text file (database1.txt) from the computer, and display the results Indicate the use of what is currently in the file if their name is in the document, if it is, then print the content of the text file, then close it, otherwise the user should prompt to enter his first name, Then the program is the same tex Writes name in the document, and then print the contents of a text file so that the user can see the newly added data. I have typed the code, and somehow it keeps saying that I have a syntax error. I checked a few times and I can not correct the error. I was thinking that a person could see and if he could be able to explain the error to me, thanks.

  # writes data from this program / database to database 1..txt file DRF database_1_reader (): print ('open1 database1.txt') f = open ('database1.txt') , 'R +') data = F.Drade (print) Print data ('What is your name in this document?') UserInput = input ('Yes or Y. for any type or no') UserInput == "No" or user input == "n" newData = input ('Please only write your first name.') F.write (newData) f = open ('database1.txt', 'r +') newReadData = F.read () New print f.close () elif userInput == "yes" Or userInput == "ye" or userInput == "y" print data f.close () Other: print ("You B 200 N !, you have not made a valid selection, try again") f.close () Input ("Any key presses to exit the program") database_1_reader ()    

< P> print py3.x has a function:
  print newReadData   

should be:

  print (newReadData)   

demo:

  & gt; & Gt; & Gt; Print "Foo" file "IPIthon-Input-1-45585431DFF", line1 print "AFU" ^ Syntex error: invalid syntax & gt; & Gt; & Gt; Print ("foo") foo   

Such statement:

  elif userInput == "yes" or user input == "you" or user Input == "Y"   

can be reduced:

  elif userInput "yes" in    

No comments:

Post a Comment