Python - Necesito ayuda para calcular valores que cambian dentro de un bucle while

 
Vista:
sin imagen de perfil

Necesito ayuda para calcular valores que cambian dentro de un bucle while

Publicado por anonymous (1 intervención) el 22/07/2018 13:46:06
No se si me explico bien en el titulo, por lo tanto lo explico aquí. Basicamente quiero hacer una calculadora de los puntos que gano en un videojuego, para eso he recurrido a python, lo que me pasa es que dentro del bucle no para de preguntar cual es la puntuacion que tienes en la siguiente partida (esto está bien), pero lo malo es que cada vez que pregunta por el nuevo valor, el programa resta el valor que introduce en usuario por el primer valor de todos que se ha escrito (el que no esta dentro del bucle while). Lo que quiero hacer es que el programa siempre se fije en el valor anterior para restar los puntos y saber cuantos puntos he ganado en referencia a la anterior partida. Espero que me haya explicado bien. Aqui está mi código. (Overwatch es el nombre del videojuego y SR es el tipo de puntos en ese videojuego)
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
starting_sr = raw_input("Type your starting SR: ")
(starting_sr)
print("Your starting SR is " + starting_sr)
def createfile():
    file=open('Overwatch SR.txt',"a")
    file.close()
createfile()
 
from datetime import *
 
datetime_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
 
def write_starting_sr():
    file=open('Overwatch SR.txt',"a")
    file.write('|--------------------------------------|\n')
    file.write("[")
    file.write(datetime_now)
    file.write("] " + "Starting SR: ")
    file.write(starting_sr)
    file.write("\n")
    file.close()
write_starting_sr()
 
while(True):
    next_game_sr = (raw_input("Type your next game SR: "))
    (next_game_sr)
 
    calculated_sr = int(next_game_sr) - int(starting_sr)
 
    if starting_sr < next_game_sr:
        print ("VICTORY " + "+" + str(calculated_sr))
 
    elif starting_sr > next_game_sr:
 
        print ("DEFEAT" + str(calculated_sr))
 
    else:
        print ("DRAW " + str(calculated_sr))
 
        if starting_sr < next_game_sr:
            def write_victory_sr():
                file=open('Overwatch SR.txt',"a")
                file.write("[")
                file.write(datetime_now)
                file.write("] ")
                file.write("VICTORY " + "+" + str(calculated_sr))
                file.write("\n")
                file.close()
                write_victory_sr()
 
        elif int(starting_sr) > int(next_game_sr):
            def write_defeat_sr():
                file=open('Overwatch SR.txt',"a")
                file.write("[")
                file.write(datetime_now)
                file.write("] ")
                file.write("DEFEAT " + str(calculated_sr))
                file.write("\n")
                file.close()
                write_defeat_sr()
 
        else:
            def write_draw_sr():
                file=open('Overwatch SR.txt',"a")
                file.write("[")
                file.write(datetime_now)
                file.write("] ")
                file.write("DRAW " + str(calculated_sr))
                file.write("\n")
                file.close()
                write_draw_sr()
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