当我从AsyncStorage获取数据时,它不会等待显示
在获取值之前返回值。
我不能在函数上使用异步等待。如果是这样,它将无法编译。
我今天整天都在搜索,但找不到答案。
我如何解决这个简单但对我来说很复杂的问题?
反应码
import random
def user_guess_validation():
guess = input('Enter your guess. Numbers seperated by a space: ')
x = guess.split() #splitting input and creating a list
if len(x) == 4: # making sure input lenght is 4
lst = []
for each in x:
if each.isdigit() == True and int(each) in range(1,10): #checking if item in list is actually a number between 1 and 9
lst.append(int(each))
print('1,the lst here is',lst)
continue
else:
print("1 Sorry,that's an invalid entry. Your guess must be 4 UNIQUE digits seperated by space.")
user_guess_validation()
for i in range(4): # checking if each input is unique
for j in range(i+1,4):
print('2,lst)
if lst[i] == lst[j]:
print('index of i and j is: ',lst[i],lst[j])
print("2 Sorry,that's an invalid entry. Your guess must be 4 UNIQUE digits seperated by space.")
user_guess_validation()
print('3,lst)
else:
print("3 Sorry,that's an invalid entry. Your guess must be 4 UNIQUE digits seperated by space.")
user_guess_validation()
def main():
secret_code = random.sample(range(1,10),4)
print(secret_code)
validated_guess = user_guess_validation()
print(validated_guess)
if validated_guess == secret_code:
print('Correct!')
else:
print('Wrong! Try again.')
user_guess_validation()
main()