Python - Error de Sintaxis (Universidad)

 
Vista:

Error de Sintaxis (Universidad)

Publicado por Antonio (1 intervención) el 07/01/2013 08:01:41
Buenos dias,

Estoy realizando un proyecto para la universidad en el que debo de usar Python, el problema es que me estoy chocando con un problema de syntax, y no acabo de tener muy claro la razon, les dejo la pieza de codigo a ver si ustedes le podrian echar un ojo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int_database=[]
def prog_int_list(int_database,CF_database):
    proj_index=0
    while proj_index<len(CF_database):
        int_sub_list=[0.0]
        CF_index=1
        val_int_t=raw_input("Are the interest rates of the project "+str(proj_index+" equal (e) or do they differ (d)? ")
        if val_int_t == "e": (Aqui es donde me dice que esta el problema)
            int_t=input("Insert the interest rate valids for all the times: ")
            while CF_index<len(CF_database[proj_index]):
                int_sub_list=int_sub_list+[int_t]
                CF_index=CF_index+1
        else:
            while CF_index<len(CF_database[proj_index]):
                int_t=input("Insert the interest rate valid for the project "+str(proj_index)+" during the period ("+str(CF_index-1)+","+str(CF_index)+"): ")
                int_sub_list=int_sub_list+[int_t]
                CF_index=CF_index+1
        proj_index=proj_index+1


Muchas gracias por su atencion.
Saludos!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 2.239
Plata
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

Error de Sintaxis (Universidad)

Publicado por xve (1646 intervenciones) el 07/01/2013 08:15:52
Hola Antonio, pero que error te da?? nos puedes indicar exactamente el error?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Error de Sintaxis (Universidad)

Publicado por Juan (1 intervención) el 06/12/2013 00:52:06
Hola, buenas tardes, soy novato con python, el interprete me esta marcando un error de sintaxis en la linea 35 es decir:

"address = None"

Agradezco de antemano cualquier tipo de ayuda. El programa es el siguiente:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# __*__ coding: UTF-8 __*__
import smbus
from time import sleep
 
# select the correct i2c bus for this revision of Raspberry Pi
revision = ([l[12:-1] for l in open('/proc/cpuinfo','r').readlines() if l[:8]=="Revision"]+['0000'])[0]
bus = smbus.SMBus(1 if int(revision, 16) >= 4 else 0)
 
# ADXL345 constants
EARTH_GRAVITY_MS2 = 9.80665
SCALE_MULTIPLIER = 0.004
 
DATA_FORMAT = 0x31
BW_RATE = 0x2C
POWER_CTL = 0x2D
 
BW_RATE_1600HZ = 0x0F
BW_RATE_800HZ = 0x0E
BW_RATE_400HZ = 0x0D
BW_RATE_200HZ = 0x0C
BW_RATE_100HZ = 0x0B
BW_RATE_50HZ = 0x0A
BW_RATE_25HZ = 0x09
 
RANGE_2G = 0x00
RANGE_4G = 0x01
RANGE_8G = 0x02
RANGE_16G = 0x03
 
MEASURE = 0x08
AXES_DATA = 0x32
 
class ADXL345:
 
    address = None
 
    def __init__(self, address = 0x53):
        self.address = address
        self.setBandwidthRate(BW_RATE_100HZ)
        self.setRange(RANGE_2G)
        self.enableMeasurement()
 
    def enableMeasurement(self):
        bus.write_byte_data(self.address, POWER_CTL, MEASURE)
 
    def setBandwidthRate(self, rate_flag):
        bus.write_byte_data(self.address, BW_RATE, rate_flag)
 
    # set the measurement range for 10-bit readings
    def setRange(self, range_flag):
        value = bus.read_byte_data(self.address, DATA_FORMAT)
 
        value &= ~0x0F;
        value |= range_flag;
        value |= 0x08;
 
        bus.write_byte_data(self.address, DATA_FORMAT, value)
 
    # returns the current reading from the sensor for each axis
    #
    # parameter gforce:
    # False (default): result is returned in m/s^2
    # True : result is returned in gs
    def getAxes(self, gforce = False):
        bytes = bus.read_i2c_block_data(self.address, AXES_DATA, 6)
 
        x = bytes[0] | (bytes[1] << 8)
        if(x & (1 << 16 - 1)):
            x = x - (1<<16)
 
        y = bytes[2] | (bytes[3] << 8)
        if(y & (1 << 16 - 1)):
            y = y - (1<<16)
 
        z = bytes[4] | (bytes[5] << 8)
        if(z & (1 << 16 - 1)):
            z = z - (1<<16)
 
        x = x * SCALE_MULTIPLIER
        y = y * SCALE_MULTIPLIER
        z = z * SCALE_MULTIPLIER
 
        if gforce == False:
            x = x * EARTH_GRAVITY_MS2
            y = y * EARTH_GRAVITY_MS2
            z = z * EARTH_GRAVITY_MS2
 
        x = round(x, 4)
        y = round(y, 4)
        z = round(z, 4)
 
        return {"x": x, "y": y, "z": z}
 
if __name__ == "__main__":
    # if run directly we'll just create an instance of the class and output
    # the current readings
    adxl345 = ADXL345()
 
    axes = adxl345.getAxes(True)
    print "ADXL345 on address 0x%x:" % (adxl345.address)
    print " x = %.3fG" % ( axes['x'] )
    print " y = %.3fG" % ( axes['y'] )
    print " z = %.3fG" % ( axes['z'] )
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar