Hi there.
I can not solve this problem:
there is a property - own[“digit”] == 5
It is necessary to make so that in a script was - 99999
if own[“digit”] == 2
then - 99
That is, the number of nines in the script match to the number in the property - own[“digit”] == 1 then 9, own[“digit”] == 6 then 999999…
Thank you for attention.
edderkop
(edderkop)
March 1, 2018, 7:23am
2
python do not have a “then” statement
if own["digit"] == 2:
own["digit"] = 9999
or maybe this is what you want
if len(own["digit"]) == 2:
own["digit"] = 99
or maybe this if its the number of digits in a int or float (the dot in a float count as a digit)
if len(str(own["digit"])) == 2:
own["digit"] = 99
edderkop
(edderkop)
March 1, 2018, 7:49am
4
is this it ?
digit = 99.1
out = ""
for c in str(digit):
out += "9"
print(int(out))
outputs: 9999
digit = 10
out = ""
for c in str(digit):
out += "9"
print(int(out))
outputs: 9999999999
wkk
March 1, 2018, 8:16am
6
digits = int(owner['digits'])
code = '9' * digits
edderkop
(edderkop)
March 1, 2018, 8:19am
7
digit = 10
out = ""
for c in range(digit):
out += "9"
print(out)
this outputs : 9999999999
edderkop
(edderkop)
March 1, 2018, 8:19am
8
i have forgotten about that.
yah that works to
TBH we just do not understand what you want…it seems like we could do it easily…but I, myself, have no clue what you are trying to do…
do you want it to output a ‘9’ for the numerical value…so the value of the property is the quantity of placeholders/digits?
1 would be one 9
2 would be two 9’s
3 would be three 9’s
etc…
so 1 = 9
2 = 99
3 = 999?
I already tried it myself:
digit = 3
out = ""
for c in str(digit):
out += "9"*digit
print(int(out))
this outputs : 999
but if the number is greater than ten, the number of nines is multiplied by two. it will be necessary to divide (reduce the number of nines by half) - expand the function (approximately):
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
digit = own["digit"]
if own["digit"] <= 9:
out = ""
for c in str(digit):
out += "9"*digit
if own["digit"] >= 10:
out = ""
for c in str(digit):
out += "9"*digit ???
print(int(out))
-I do not yet know how to solve the problem with the number >= 10
Cotaks
(- Click for (UP)Bge resources)
March 1, 2018, 8:42am
12
Here:
you need to for loop the variable you set, then append to a list then joint that list into a string.
count = 10
output = []
for i in range(count):
output.append(9)
end_result = ''.join(str(entry) for entry in output)
print(end_result)
change count to any number you like, it will add that many 9’s to the end_result
I guess I made my example (future) a bit complicated:
so to speak:
I have a 1234
how to make them? - 9999
or 123456
to do 999999
so it is easier to use - minus one property.
edderkop
(edderkop)
March 1, 2018, 8:46am
14
digits = 20
out = '9' * digits
print(int(out))
outputs 20 digits: 99999999999999999999
edderkop
(edderkop)
March 1, 2018, 8:50am
15
that’s easy
digits = len(str(own["digit"]))
own["digit"] = "9" * digits
Cotaks:
Here:
you need to for loop the variable you set, then append to a list then joint that list into a string.
count = 10
output = []
for i in range(count):
output.append(9)
end_result = ''.join(str(entry) for entry in output)
print(end_result)
change count to any number you like, it will add that many 9’s to the end_result
the goal! Working. I thank everyone for their help.
Сan help with this (I simplified the example) - #13
Cotaks
(- Click for (UP)Bge resources)
March 1, 2018, 8:55am
17
actually i did not read the whole topic and Wknight02/edderkop has an faster/better solution
digits = 20
out = '9' * digits
print(int(out))
does actually the same thing as my script does
here is the working solution for the main question:
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
digits = int(own["digit"])
own["prop"] = '9' * digits
print(own["prop"])
if own[“digit”] = 20
output = 99999999999999999999
I thank everyone for solving the main issue.
Cotaks
(- Click for (UP)Bge resources)
March 1, 2018, 9:17am
20
here is the working solution for the main question:
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
digits = int(own["digit"])
own["prop"] = '9' * digits
print(own["prop"])
if own[“digit”] = 20
output = 99999999999999999999
I thank everyone for solving the main issue.
Here use this for you other question
digits = 532
count = len(str(digits))
out = '9' * count
print(int(out))
this wil convert 532 into 999 so one 9 per digit.
or 123456789 to 999999999, etc