Home > other >  Code to run the results do not conform to the requirements, ask for help
Code to run the results do not conform to the requirements, ask for help

Time:10-10

# # read a Python source file, the file of all except the reserved words lowercase letters to uppercase
# # is generated after the file is to be able to the Python interpreter executed correctly

# building reserved word list
The import keyword
S=keyword. Kwlist

W # building built-in function list, add all built-in functions to reserved word list s
W=dir (__builtins__)
For I in range (len (w)) :
[I] s.a ppend (w)
S.a ppend (' (input) # to add a Python source file reserved words, a custom function outside of the parameters of Python
S.a ppend (' sum) ') # baidu to Python writing standards: element in the bracket must with left, right bracket, such as: (a, b) correct; (a, b) is not correct
Enter a file name: n=input (' ')

# to create a list of all the words for elements per line group
F=open (n, r, encoding="utf-8"). The readlines ()
Ls=[i. plit () for I f] in four line # @ # @ code of shorthand
# @ @ ls=[]
# @ @ for I f in:
# @ @ I=i. plit ()
# @ @ ls. Append (I)

# # fw=open (n, 'r')
# # for I in range (len (ls)) :
# # for j in range (len (ls) [I]) :
# # x=ls [I] [j]
# # print (x)

# traversal two-dimensional list, changed the ordinary words lowercase capital
Fo=open (n, 'w' + ')
For I in range (len (ls) :
If f [I] isspace () : # STR. Isspace () : if the string contains only whitespace, return True, otherwise False
Xsl-fo. Write (' + '\ n')
For j in range (len (ls) [I]) :
X=ls [I] [j]
If x is not in s:
X=x.u pper ()
The else:
X=x
# will be revised list in file (cover) note: ":" after the inclusion relation
If x==ls [I] [len (ls [I]) - 1) : # determine whether traverse to the end of each line
If x==': :
Xsl-fo. Write (x)
Xsl-fo. Write (' \ n ')
Fo. Write (') # judge whether inclusion relation
The else:
Xsl-fo. Write (x)
Xsl-fo. Write (' \ n ')
The else:
Xsl-fo. Write (x + ')
# # fo. Seek (0)
# # for the line in fo:
# # print (line)
Xsl-fo. Close ()

# # # # # # # # # # # # # # # # source code # # # # # # # # # # # # # # # # # #
# # n=int (input (" please enter an integer: "))
# # sum=0
# # for I in range (n) :
# # sum +=I + 1
# # print (" 1 to {} and additive is {} ". The format (n, sum))

To run the program and get results:
N=int (input (" please enter an integer: "))
Sum=0
For I in range (N) :
The sum +=I + 1 print (" 1 to the addition of {} {} "is the sum of the format (N, sum))

Two questions: 1, deal with the last line breaks
2, the source code to participle deliberately played a lot of space, although the source code can run normally, but I don't know the source code is in accordance with the specification,
A great god, please give directions,

CodePudding user response:

If the source code to:

Def (f) :
Try:
N=int (input (" please enter an integer: "))
Except:
Print (" input is unusual, please input again: ")
Return (f)
S=0 # # # s calculator, put in circulation outside: s initialized only once to 0
For I in range (2, n) :
S=0 # calculator s, put inside loop: external loop every cycle, s is assigned a 0 a
For j in range (2, I + 1) :
If I % j==0:
S +=1
If s==1:
Print (I, end="")
F ()

Problem: 1, 'def f () : the following statements, judging by a colon indentation not make, what a great god has good treatment method?
2, the except:
Print (" input is unusual, please input again: ")
Return (f)
A colon followed by two indentation statement code?

CodePudding user response:

2 building code writing is not standard, direct reference to participle, please increase the space,
  • Related