How to make random nextInt work in Kotlin? [closed] - android-studio

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
So I try using "nextInt" but it just counts as an Error and my app won't start please help!
val randomValues = List(1) { Random.nextInt(0, 10) }
I tried Importing "nextInt" but it does nothing, it just marks it as an error.

Kotlin has its own version of the Random utility class:
import kotlin.random.Random
class Main {
fun main(args: Array<String>) {
val randomValues = List(1) { Random.nextInt(0, 10) }
}
}

Related

Get A Response From A Result (CURL) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
I'm noobie/beginner at Python
I was creating this script
I tried to curl a URL and got a response(A)
now I want to get the response(B) from that response A
result = os.popen("curl https://raw.githubusercontent.com/SirdLay/test/main/test.txt").read()
index = os.popen("curl [what to be used here?]")
response1 = os.popen("curl https://raw.githubusercontent.com/SirdLay/test/main/test.txt").read()
url = response1[<key>]
# key is some key in the response1.
# You can print the response1 to see the object.
# For your particular case you dont need a key.
# so you can use
url = response1
response2 = os.popen("curl " + url).read()

In name == 'main', why is variables shared in class? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Well, I just noticed that variables in if name == 'main': are shared to the classes in the same file - why is this? I don't recall having this issue in python2...
class A:
def __init__(self, b):
self.b = b
def func_a(self):
return d
if __name__ == '__main__':
classA = A(1)
d = 2
print(classA.func_a())
prints out 2.
What's the reasoning?
this definitely also happens in python2
and is very simple: declaring variables outside of functions/classes makes them global and when python searches for variables with the name d it doesn't find it in the local scope but it does find the global variable

when i write the command this error i see [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
cur.execute(command, tuple(values))
if (fetch := cur.fatchone()) is not None:
return fetch[0]
#bot_has_permissions(manage_roles=True)
#has_permissions(manage_roles=True, manage_guild=True)
async def unmute_members(self, ctx, members: Greedy[Member], *, reason: Optional[str] = "لا يكثر هرجك"):
if not len(members):
await ctx.send("!unmute #member [reason]")
else:
await self.unmute(ctx, members, reason=reason)
AttributeError: 'sqlite3.Cursor' object has no attribute 'fatchone'
Typo.
if (fetch := cur.fatchone()) is not None:
should be
if (fetch := cur.fetchone()) is not None:

Datetime is not equal to itself in Python [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I created a simple program to python that check if this X is expired.
import datetime
expired_on = datetime.datetime.now() + datetime.timedelta(0, 20) # add 20 seconds for expiration time
while True:
X = datetime.datetime.now()
if expired_on == X:
print(f"this {X} is expired.")
break
but it didn't break after 20 seconds.
This will be much cleaner.
import datetime
expired_on = datetime.datetime.now() + datetime.timedelta(seconds=20) # Add 20 seconds for expiration time
while True:
now = datetime.datetime.now()
if expired_on <= now:
print('Expired.')
break

the python problems about strings [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
def shut_down(s):
s = s.Lower()
if s == 'yes' :
return "Shutting down..."
elif s == 'no':
return "Shutdown aborted!"
else :
return "Sorry, I didn't understand you."
the computer tell me that Your shut_down function threw the following error: 'str' object has no attribute 'Lower'
Your .Lower() is not available in python because it's case sensitive language use .lower()
def shut_down(s):
s = s.lower()
if s == 'yes' :
return "Shutting down..."
elif s == 'no':
return "Shutdown aborted!"
else :
return "Sorry, I didn't understand you."

Resources