Flag control variable

luke.geelen at gmail.com luke.geelen at gmail.com
Tue Feb 11 13:37:45 EST 2014


well i'm trying something else but no luck :

#!bin/bash/python
import sys
import os
a = int(sys.argv[1])
sign = (sys.argv[2])
b = int(sys.argv[3])

if sign == '+':
  sum = a + b
  print a, sign, b, "=", a + b
  command1 = "sudo mpg321  'http://translate.google.com/translate_tts?tl=en&q=%s_plus%s_equals%s'" % (a, b, sum)
  os.system (command1)

elif sign == "*":
  sum = a * b
  print a, sign, b, "=", a * b
  command1 = "sudo mpg321  'http://translate.google.com/translate_tts?tl=en&q=%s_times%s_equals%s'" % (a, b, sum)

when using * i get 

Traceback (most recent call last):
  File "./math+.py", line 6, in <module>
    b = int(sys.argv[3])
ValueError: invalid literal for int() with base 10: 'Adafruit-Raspberry-Pi-Python-Code'

i don't understand why b is a problem, it works fine with +



More information about the Python-list mailing list