water=[2,3,4,5]
fire=[6,7,8,9]
list_redblue=[water, fire]
answer=input('input=')
if answer in list_redblue:
print(answer)
else:
print('You have entered it incorrectly.')
When I was fire have been entered, or water here.
출력값을 [2,3,4,5]
또는 [6,7,8,9]
로 하고싶은데
w a t e r just so
is printed.
What code should I write?
Python! I'm starting now, New B.
python
#python3.8
water = [2,3,4,5]
fire = [6,7,8,9]
list_redblue=[water, fire]
answer = input('input :')
if answer in list_redblue:
try:
print(locals()[answer]) #
except:
print('No!')
else:
print('Wrong :(')
It is not good to input the variable name defined in the program and output the value of the variable name.
Variable names must be independent of program behavior. What I mean is that I don't like the variable name water
so it's better to work the same way even if I change it to washer
later.
If you enter water
and you want [2, 3, 4, 5]
to be output, like this....
data = { "water":[2, 3, 4, 5], "fire":[6, 7, 8, 9] }
answer = input("input :")
if answer in data:
print(data[answer])
else:
print("Wrong :(")
© 2024 OneMinuteCode. All rights reserved.