phonevalue=0 if (condition== "new"): phonevalue=int(phonevalue+10) else: phonevalue=int(phonevalue+9) if gps==bool(input("true")): phonevalue=int(phonevalue+1) else: phonevalue=int(phonevalue) if wifi==eval(bool(input("true"))): phonevalue=int(phonevalue+1) else: phonevalue=int(phonevalue) if camera==eval(bool(input("true"))): phonevalue=int(phonevalue+1) else: phonevalue=int(phonevalue) global phonevalue
this code. supposed able input condition, gps, camera, , wifi , code evaluates input , gives points each condition. if phone new gets ten points , if used gets nine. gps, camera, , wifi wants me use boolean either give point true or no points false. wondering how convert input string boolean in order add phone value?
there's lot wrong in code. firstly, input()
command defined
input([prompt])
if prompt argument present, written standard output without trailing newline.
which means call input("true")
prints "true" on console , waits line of input. that's not hoping for.
your use of eval
bad. every use of eval
on user input problem. saved here accident: eval(bool(text))
superfluous. thing bool()
can return true
or false
neither of dangerous eval, since had boolean in hand, eval'ing didn't anything.
converting result of integer addition int()
useless, , if / else clauses can more written as:
if input("is there gps? "): phonevalue += 1
with no else
clause needed. unfortunately, has no chance of getting correct input. if type "true" if
block trigger. trigger if write "no", "false", or "josedusol", evaluated true
also. declaration @ end
global phonevalue
does absolutely nothing last line. in fact, should forget global
exists because uses incorrectly.
there more faults in code, , should assistance teacher or better learning resource.
Comments
Post a Comment