mardi 29 janvier 2019

Python - If Statement With input() Not Functioning Inside def() Function

Everything in the code runs properly except def a() and def b() have and if statements that examine and input() function though when I run the code it will lead to 'good for you' being printed no matter the input. For instance if I type False or Whatever into the code which should lead to different results, both lead to the response 'good for you' as though the input is always True or true. I haven't been coding for very long so excuse me if this is an obvious fix.

    tsil = ['input',]

while True:
  print('Write A Number (Print "done" When Finished)')
  num = input()
  tsil.append(num)
  print()
  if num == 'done':
    break

if True == True:
  print(tsil)

def a():
  print('you like short lists? (True or False)')
  ans = input()
  if ans == 'True' or 'true':
    return '\ngood for you'
  elif ans == 'False' or 'false':
    return '\nstop making short lists then'
  else:
    return '\nstop printing the wrong things loser'


def b():
  print('you like long lists? (True or False)')
  ans = input()
  if ans == 'True' or 'true':
    return '\ngood for you'
  elif ans == 'False' or 'false':
    return '\nstop making short lists then'
  else:
    return '\nstop printing the wrong things loser'

if len(tsil) < 10:
  print('^ short list large gorge')
  print()
  print(a())
else:
  print('^ big boy list')
  print()
  print(b())

Aucun commentaire:

Enregistrer un commentaire