python invalid syntax in comment -


using idle python 3.4.3. script gives user small quiz, calculates how many got right. i'm having invalid syntax error in comment before script runs. here whole code around comment. specific comment under line score = decimal.decimal(score):

score = amountright/7*100 """this takes amount of questions user got right, divides 7 (the total number of questions), multiplies 100 percentage correct , stores in variable score""" import decimal """this import function round off final percentage whole number instead of unnecessarily long decimal""" score = decimal.decimal(score) """this redefines score variable sort of roundable decimal. round() function in line below still function without line, print unneeded .0 before %""" print ("you got " + str(amountright) + " out of 7 right, or " + str(round(score,0)) + "%.") """the round() function works rounding first argument n places in second argument""" 

i run this, invalid syntax error, highlights s , c in word score red. using ' makes no difference in this. however, when run code this:

""" redefines score variable sort of roundable decimal. round() function in line below still function without line, print unneeded .0 before % """ 

it still gives syntax error, time highlights s in score red. repr added unutbu's request:

print ("here quiz!\n") #starting prompt  useranswer = input("question 1: 4+|6x1|? ") #this user enters answer question  #the following 2 variables on lines 7 , 9 need defined once rightanswerresult = "correct! next question:\n" #tells user correct invalidanswerresult = "this not number. counted wrong answer.\n" """if user not answer number, string print telling them , question counted wrong"""  amountright = 0 #this number increases every time user answers question correctly  if useranswer.isdigit(): #if user's answer number, code below runs     if useranswer == "10":     #this checks if user's answer , correct answer same, runs code below if are"""         print (rightanswerresult) #this prints variable rightanswerresult described on line 7         amountright += 1 #this add value 1 variable amountright described on line 13     else: #if user's answer , correct answer not same, code below runs         print ("wrong, 10. next question:\n") #tells user wrong else: #if user's answer not number, runs     print (invalidanswerresult) #this prints varible invalidanswerresult described in line 9 #this pattern repeated 5 more times. altered process used true/false question (#7) useranswer = input("question 2: (15/3) x 12? ") if useranswer.isdigit():     if useranswer == "60":         print (rightanswerresult)         amountright += 1     else:         print ("wrong, 60. next question:\n") else:     print (invalidanswerresult)  useranswer = input("question 3: 20+24/12? ") if useranswer.isdigit():     if useranswer == "22":         print (rightanswerresult)         amountright += 1     else:         print ("wrong, 22. next question:\n") else:     print (invalidanswerresult)  useranswer = input("question 4: solve x: 2x-1=5 ") if useranswer.isdigit():     if useranswer == "3":         print (rightanswerresult)         amountright += 1     else:         print ("wrong, 3. next question:\n") else:     print (invalidanswerresult)  useranswer = input("question 5: square root of 256? ") if useranswer.isdigit():     if useranswer == "16":         print (rightanswerresult)         amountright += 1     else:         print ("wrong, 16. next question:\n") else:     print (invalidanswerresult)  useranswer = input("question 6: 7x7+7/7-7? ") if useranswer.isdigit():     if useranswer == "1":         print (rightanswerresult)         amountright += 1     else:         print ("wrong, 1. next question:\n") else:     print (invalidanswerresult) #the question below appears different because true/false , last question useranswer = input("question 7: true or false: |3|=98/2 ").lower() #as before, user asked question if useranswer == "false": #checks if user's answer false, , runs code below if     print ("you're right! results below:\n") #this tells user correct shows them final score     amountright += 1 #as before, add value 1 variable amountright described on line 8 if useranswer == "true": #checks if user's answer true, , runs code below if     print ("actually, false. results below:\n") #this tells user wrong shows them final score elif useranswer != "false" , useranswer != "true": #if user's answer not true or false, code runs     print ("it seem didn't enter true or false. maybe made spelling error? anyways, results below:\n")     """tells user answer invalid shows final score""" #all questions have been completed. below final score calculation score = amountright/7*100 """this takes amount of questions user got right, divides 7 (the total number of questions), multiplies 100 percentage correct , stores in variable score""" import decimal """this import function round off final percentage whole number instead of unnecessarily long decimal""" score = decimal.decimal(score) """this redefines score variable sort of roundable decimal. round() function in line below still function without line, print unneeded .0 before %""" print ("you got " + str(amountright) + " out of 7 right, or " + str(round(score,0)) + "%.") """the round() function works rounding first argument n places in second argument""" 

is there error comment?

# used indicate start of comment. triple quotes used indicate start , end of multiline strings. although strings not comments, multiline strings can used multiline comments.

however, placement of string still has abide python syntax rules.

score = amountright/7*100 """this takes amount...""" 

raises syntaxerror because string follows expression not string. amountright/7*100 """this takes amount...""" equivalent

>>> 1 "foo" syntaxerror: invalid syntax 

python not know how evaluate number followed string. if evaluated, value assigned score. multiline string not interpreted comment. multiline string act comment must on line itself:

score = amountright/7*100  """this takes amount of questions user got right, divides 7 (the total number of questions), multiplies 100 percentage correct , stores in variable score"""  import decimal  """this import function round off final percentage whole number instead of unnecessarily long decimal""" 

or, use more commonly used comment syntax:

score = amountright/7*100  # takes amount of questions user got right, divides 7 (the # total number of questions), multiplies 100 percentage # correct , stores in variable score 

putting # in front of every line might seem pain, text editor programming in python should have way select region of text , press button or key combination insert # signs you. if editor not have feature, find 1 does.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -