0

How to make a variable like n=1,2,3,4,5... In PY

If i/k = n I the code to know that that n can be any of the natural numbers.

7th Nov 2023, 11:53 PM
Kreshnik Feka
Kreshnik Feka - avatar
4 Respostas
+ 3
Your try first... Learn about range() function to create a range of values... one simple way.
8th Nov 2023, 3:47 AM
Jayakrishna 🇮🇳
+ 3
Kreshnik Feka, It would be very helpful if you can do a sample for us (code or pseudo code), also try to give us more details. Thanks!
8th Nov 2023, 6:15 PM
sandra
sandra - avatar
+ 1
In Python you can use the sympy library to represent expressions in symbolic algebra. https://docs.sympy.org/latest/tutorials/intro-tutorial/intro.html#what-is-symbolic-computation As a more general technique, you can use assertions (assert keyword) to enforce certain conditions on variable values. You can use error handling (try and except keywords) to determine what the programs should do, when the conditions are not fulfilled or an illegal operation happens. You can encapsulate your variable in a class and write validations in the __init__ method or in the property setter, to make sure that illegal values cannot be assigned.
8th Nov 2023, 3:54 AM
Tibor Santa
Tibor Santa - avatar
0
you must use a 'for' loop
9th Nov 2023, 7:36 PM
jhoanix