我正在创建一个程序,您可以在其中输入密码,然后就可以玩游戏了。在我的一个定义riddle()
中,它告诉我d1
, d2
, d3
,d4
和d5
在定义之前被引用,但据我所知,它们已经被定义。此外,当这仍然有效时,我试图让它解决一个任务会让它说它已经完成,但是当我完成一个时,它仍然说 1 不完整等等。我需要解决这两个问题。
def riddle():
d1 = 'n'
d2 = 'n'
d3 = 'n'
d4 = 'n'
d5 = 'n'
def compcheck():
print('There are 5 tasks to complete. Enter a number to see task.')
if d1 in ('y'):
t1 = 'Completed.'
if d2 in ('y'):
t2 = 'Completed.'
if d3 in ('y'):
t3 = 'Completed.'
if d4 in ('y'):
t4 = 'Completed.'
if d5 in ('y'):
t5 = 'Completed.'
if d1 in ('n'):
t1 = 'Incomplete.'
if d2 in ('n'):
t2 = 'Incomplete.'
if d3 in ('n'):
t3 = 'Incomplete.'
if d4 in ('n'):
t4 = 'Incomplete.'
if d5 in ('n'):
t5 = 'Incomplete.'
print ('1 is ' + t1)
print ('2 is ' + t2)
print ('3 is ' + t3)
print ('4 is ' + t4)
print ('5 is ' + t5)
def solve():
compcheck()
if d1 and d2 and d3 and d4 and d5 in ['y']:
print ('The password is 10X2ID 4TK56N H87Y8G.')
tasknumber = input().lower()
if tasknumber in ('1'):
print('Fill in the blanks: P_tho_ i_ a c_d_ng lan_u_ge. (No spaces. Ex: ldkjfonv)')
task1ans = input().lower()
if task1ans in ['ysoinga']:
d1 = 'y'
solve()
if tasknumber in ('2'):
print('Is the shape of a strand of DNA: A): a Lemniscate, B): a Hyperboloid, C): a Double Helix, or D): a Gömböc.')
task2ans = input().lower()
if task2ans in ['c']:
d2 = 'y'
solve()
if tasknumber in ('3'):
print ('What is the OS with a penguin mascot?')
task3ans = input().lower()
if task3ans in ('linux'):
d3 = 'y'
solve()
if tasknumber in ('4'):
print('')
if tasknumber in ('5'):
print('')
solve()