如何根据条件在Jupyter Notebook中显示gif图像?
How to diplay gif image in Jypyter Notebook based on conditions?
问题:我正在尝试创建一个简单的测验并根据分数显示 gif 图像。
请参阅下面的分数类别:
- 满分:5
- 很棒:5
- 不错:3 - 4
- 差:0-2
我可以使用以下方法显示单个 gif
from IPython.display import Image
Image(url='https://images.gr-assets.com/hostedimages/1555943935ra/27397694.gif', width=375, height=200)
但是,我能够根据以下逻辑获得显示的gif。希望有人能帮我解决这个问题。谢谢!
if score==5:
Image(url='https://images.gr-assets.com/hostedimages/1555943935ra/27397694.gif', width=375, height=200)
print("Awesome!")
elif score>2 and score<=4:
Image(url='https://media3.giphy.com/media/l0HepmE7eqiK86GSQ/giphy.gif?cid=ecf05e473mzzo1br8w9didsqr5j34nruzuks3wlvxmxf2zse&rid=giphy.gif', width=375, height=200)
print("Not bad!")
if score<=2:
Image(url='https://media1.tenor.com/images/ea96c313bbb74cc69abc861e21ee3098/tenor.gif', width=375, height=200)
print("Bad!")
使用display
绘制图像。
if score==5:
img = Image(url='https://images.gr-assets.com/hostedimages/1555943935ra/27397694.gif', width=375, height=200)
display(img)
print("Awesome!")
elif score>2 and score<=4:
img = Image(url='https://media3.giphy.com/media/l0HepmE7eqiK86GSQ/giphy.gif?cid=ecf05e473mzzo1br8w9didsqr5j34nruzuks3wlvxmxf2zse&rid=giphy.gif', width=375, height=200)
display(img)
print("Not bad!")
elif score<=2:
img = Image(url='https://media1.tenor.com/images/ea96c313bbb74cc69abc861e21ee3098/tenor.gif', width=375, height=200)
display(img)
print("Bad!")
问题:我正在尝试创建一个简单的测验并根据分数显示 gif 图像。 请参阅下面的分数类别:
- 满分:5
- 很棒:5
- 不错:3 - 4
- 差:0-2
我可以使用以下方法显示单个 gif
from IPython.display import Image
Image(url='https://images.gr-assets.com/hostedimages/1555943935ra/27397694.gif', width=375, height=200)
但是,我能够根据以下逻辑获得显示的gif。希望有人能帮我解决这个问题。谢谢!
if score==5:
Image(url='https://images.gr-assets.com/hostedimages/1555943935ra/27397694.gif', width=375, height=200)
print("Awesome!")
elif score>2 and score<=4:
Image(url='https://media3.giphy.com/media/l0HepmE7eqiK86GSQ/giphy.gif?cid=ecf05e473mzzo1br8w9didsqr5j34nruzuks3wlvxmxf2zse&rid=giphy.gif', width=375, height=200)
print("Not bad!")
if score<=2:
Image(url='https://media1.tenor.com/images/ea96c313bbb74cc69abc861e21ee3098/tenor.gif', width=375, height=200)
print("Bad!")
使用display
绘制图像。
if score==5:
img = Image(url='https://images.gr-assets.com/hostedimages/1555943935ra/27397694.gif', width=375, height=200)
display(img)
print("Awesome!")
elif score>2 and score<=4:
img = Image(url='https://media3.giphy.com/media/l0HepmE7eqiK86GSQ/giphy.gif?cid=ecf05e473mzzo1br8w9didsqr5j34nruzuks3wlvxmxf2zse&rid=giphy.gif', width=375, height=200)
display(img)
print("Not bad!")
elif score<=2:
img = Image(url='https://media1.tenor.com/images/ea96c313bbb74cc69abc861e21ee3098/tenor.gif', width=375, height=200)
display(img)
print("Bad!")