Python - unexpected indent python

 
Vista:
sin imagen de perfil
Val: 2
Ha disminuido su posición en 7 puestos en Python (en relación al último mes)
Gráfica de Python

unexpected indent python

Publicado por Santiago (1 intervención) el 13/12/2020 19:05:52
Hola muy buenas, tengo que resolver un ejercicio para programación y me he quedado muy estancado, el ejercicio lo debemos resolver mediante "excepciones (try/except)" y actualmente tengo gran parte avanzado pero me he quedado bloqueado en un punto y no sé como seguir. Si alguien me pudiera ayudar a resolver el problema sería de gran ayuda ^^. Les dejo una foto del ejercicio y el código que tengo escrito de momento tanto en imagen y .rar como en escrito y enlace al ejercicio :D

http://www.hnilica.wz.cz/homeworks/HW_08.pdf

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
# creation of the list
correct = False
print("insert the number of elements (<0): ", end = " ")
while not correct:
    try:
        n = int(input())
        L = [0] * n
        if n > 0 and int:
            print("now we have a list containing {} zeros".format(n))
            correct = True
        else:
            print(n, "is out of range, try it again: ", end = " ")
    except ValueError as e:
        print(e,"is not a number, try it again: ", end = " ")
 
 
 
# changing of values
finish = False
fnInd = False
finval = False
 
print("\ndo you want to change any value? <0/1>: ", end = " ")
 
while not finish:
    try:
        choice = int(input())
        if choice == 0:
            finish = True
        else:
            if choice != 1:
                print(choice, "is out of range, try it again: ", end = " ")
            else:
                finInd = False
                print("insert index: ", end = " ")
                while not finInd:
                    try:
                        index = int(input())
                        if index <= n:
                            finInd = True
                        else:
                            if index > n:
                                print(index, "is out of range, try it again: ", end = " ")
                            else:
                                finval = False
                                print("insert value (<1000): ", end = " ")
                                while not finval:
                                    try:
                                        value = int(input())
                                        if value < 1000:
                                            finval = True
                                        else:
                                            if value > 1000:
                                                print(value, "is out of range, try it again: ", end = " ")
L[index] = value
 
 
# calculation, output
 
mean = sum(L) / len(L)
print("\nlist:", L)
print("mean of values is", mean)
HW8
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
sin imagen de perfil
Val: 2.808
Oro
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

unexpected indent python

Publicado por tincopasan (1082 intervenciones) el 13/12/2020 23:12:45
supongo que han visto el uso de funciones, sino el código se haría muy largo.
le hice los agregados de verificación, cualquier texto cambialo por el que quieras.
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
#-*- coding: utf - 8 -*-
 
# creation of the list
 
def verifica(numero):
    while True:
        try:
            numero = int(numero)
            return numero
        except:
            numero = input("is not a number, try it again: ")
 
n = verifica(input("insert the number of elements (<0): "))
L = [0] * n
print("now we have a list containing {} zeros".format(n))
 
 
# changing of values
finish = False
 
while not finish:
    choice = verifica(input("\ndo you want to change any value? <0/1>: "))
    if choice == 0:
        finish = True
    elif choice == 1:
        index = verifica(input("Index: "))
        value = verifica(input("Value: "))
        if index > len(L):
            print("error index")
        elif value > 1000:
            print("error value")
        else:
            L[index] = value
 
    else:print("wrong choice")
 
 
# calculation, output
mean = sum(L) / len(L)
print("\nlist:", L)
print("mean of values is", mean)

dicho sea de paso, todo el desarrollo del ejercicio es como viejo, no usan lo nuevo o ahorro de memoria, en fin.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar