考虑:
x =. 0 1 2 3 4 1 3 4 99
v =. [ {.~ (>: @ i.&1 @ (#@~. = #\))
v x NB. => 0 1 2 3 4 1
行为是正确的。但正如你所看到的,v
是可耻的冗长。有更好的解决方案吗?
答案 0 :(得分:5)
你想要monad import random
cond = True
while cond:
print('Hello there! Please enter a number between 1 and 9 including the extremes.')
x=random.randint(1,9)
for i in range (10):
z=int(input())
if int(z)<x:
print('Too low. Please try again.')
elif int(z)>x:
print('Too high. Please try again.')
elif int(z)==x:
print('You guessed it right!')
import sys
if i==0:
print('It took you a single turn! Nice')
else:
print('it took you ' + str(i+1)+' turns.')
print('Do you want to play again? Yes or No?')
j=input()
if j.lower()=='yes':
break
else:
cond = False
sys.exit()
(nub sieve):
~:
代码审核:
v =: {.~ 1 + 0 i.~ ~:
x =: 0 1 2 3 4 1 3 4 99
v x
0 1 2 3 4 1
代替#\
。它太可爱了,难以维护,并且不会被特殊代码优化器识别。i.@#
,x
,y
,u
,v
或m
(特殊情况除外)环境,并且总是在明确的背景下本地化。)