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.
4 Respostas
+ 2
points = 25
go = true
while go:
val = input()
try:
val = int(val)
points = points + val
except:
print("not integer, continu")
+ 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...
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!
- 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