Skip to main content

Thread: python syntax help


hey guys. im beggining python programmer , want make mesurment converter i. e. how many inches in foot. when try run it, says invalid syntax. heres code
code:
from sys import argv    input, output, = argv      if input = "feet" , output = "inches" print "12"

code:
input, output, = argv if input = "feet" , output = "inches" print "12"
both of these lines have incorrect syntax, , if correct, doubt they'd want.

first off, first line has comma after output. after corrected, fail if program has more or less 1 argument. because unpacking throw error if there more values in list/tuple/etc. variables unpack to. also, first value of argv name of script, not argument. first , second arguments of script, use these lines.
code:
from sys import argv try:     arg1=argv[1]     arg2=argv[2] except indexerror: #not enough arguments.     print "you must pass in @ least 2 arguments."     exit(1)
the second line doesn't have colon after if statement. throw error if statement execute on next line , indented. also, = throw error because assignment symbol, not comparison symbol. use == instead.
code:
if arg1=="feet" , arg2=="inches": print "12"
here program trying write in pseudocode, handling feet, inches, , yards. leave translating python challenge you.
code:
try {     arg1=arguments[1].lowercase()     arg2=arguments[2].lowercase() } except notinarray {     print "not enough arguments."     exit(1) }  #these in terms of inches. units=array(     "inches" = 1,     "feet" = 12,     "yards" = 36 )  try {     print units[arg2]/units[arg1] } except notinarray {     print "invalid units."     exit(1) }


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] python syntax help


Ubuntu

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account