if else 条件显示 python 中的图像

if else condition display images in python

我必须在 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)

您可以使用IPython.display.display显示图像:

print("What invention lets you look right through a wall") 
ans = ["window", 'Window','WINDOW']

respond = input() 
from IPython.display import Image, display

window_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Window_of_the_house_with_number_17_on_strada_M%C3%A2ntuleasa%2C_from_Bucharest_%28Romania%29.jpg/117px-Window_of_the_house_with_number_17_on_strada_M%C3%A2ntuleasa%2C_from_Bucharest_%28Romania%29.jpg"
door_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Pohjolan_talo_-_Marit_Henriksson_1.jpg/526px-Pohjolan_talo_-_Marit_Henriksson_1.jpg"

if respond in ans:
    display(Image(data=window_url, width=200, height=200))
else: 
    display(Image(data=door_url, width=200, height=200))