【发布时间】:2022-01-18 11:36:54
【问题描述】:
我必须在 python 代码中为这个谜语显示 2 个不同的图像。但是图像没有显示在 python jupyter notebook 中。它继续处理并且不显示错误。 有人可以指导我,如何在接受用户输入时在 if else 条件下显示 2 个不同的图像。
代码:
print("What invention lets you look right through a wall")
ans = ["window", 'Window','WINDOW']
respond = input()
from IPython.display import Image
if respond in ans:
Image(url= "window.jpg", width=200, height=200)
else:
Image(url= "cat_meme.jpg", width=200, height=200)
【问题讨论】:
-
只是一个旁注,做类似
ans = 'window'的事情会更容易,然后在if中检查if respond.lower() == ans: