0

How do I make my variable equal the input forever?

What I mean is how do I make the number equal the input even for the next input. For example, I want the following program to store a number in variable with points and a new integer input. points = 25 x = points + int(input()) print(x) Now, if I input 10, I want x to equal 35 forever. So if I inputted another 10, it would equal to 45.

24th Sep 2021, 3:26 PM
Zane Al-Hamwy
Zane Al-Hamwy - avatar
4 Respuestas
+ 2
points = 25 go = true while go: val = input() try: val = int(val) points = points + val except: print("not integer, continu")
24th Sep 2021, 11:08 PM
Elon
Elon - avatar
+ 1
If you mean that you want to save a certain value and add to it the input each time you run the code then you have to store that value in an external file (txt file for example) Python variables in your code will be cleared after finishing running so there's no way to save in it a value forever...
24th Sep 2021, 4:14 PM
Abdelrahman Tlayjeh
0
Zane Al-Hamwy If you increase the value of points as much as 10 each time, just enter an increment value as integer. Then, you'll see the last value of points. Here, the code lines: points = 25 x = int(input()) i = 0 while i <= x: points += 10 i += 1 print(points) Happy coding!
24th Sep 2021, 5:56 PM
mesarthim
mesarthim - avatar
- 1
The 'forever' word is quite confusing here. Can you be more specific ? If you want to save the value of x as 35 inside of a certain program only, it will be 35, forever unless you re-assign it's value If you want to save its value everywhere, like that of universal contstants like pi or e, you can't ! Wht you can do is store 'x=35' in a file and import it, whenever you need it
24th Sep 2021, 6:33 PM
Sacar
Sacar - avatar