|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
问题:
1. 创建另一个名为 roll_and_show 的函数。
2. 该函数应该使用 throw_dice 函数来掷骰子。
3. 之后,该函数应调用 show_roll 函数以将您投掷的数字显示为图像。
提示代码:
#Import libraries
from PIL import Image
import requests
from io import BytesIO
import random
#Dice side image URLs
roll1_url = r"https://cdn-icons-png.flaticon.com/128/7011/7011091.png"
roll2_url = r"https://cdn-icons-png.flaticon.com/128/7011/7011093.png"
roll3_url = r"https://cdn-icons-png.flaticon.com/128/7011/7011095.png"
roll4_url = r"https://cdn-icons-png.flaticon.com/128/7011/7011097.png"
roll5_url = r"https://cdn-icons-png.flaticon.com/128/7011/7011099.png"
roll6_url = r"https://cdn-icons-png.flaticon.com/128/7011/7011104.png"
#Get images from URLs
roll1 = requests.get(roll1_url)
roll2 = requests.get(roll2_url)
roll3 = requests.get(roll3_url)
roll4 = requests.get(roll4_url)
roll5 = requests.get(roll5_url)
roll6 = requests.get(roll6_url)
我的报错代码:
Import libraries
from PIL import Image
import requests
from io import BytesIO
import random
import random
num = random.randint(1,6)
roll_images = [roll1, roll2, roll3, roll4, roll5, roll6]
roll_im = roll_images[num-1]
img = Image.open(BytesIO(roll_im.content))
def show_roll(num):
【
img.thumbnail([50,50])
display(img)
】
for n in image[num - 1]:
print(n)
print()
def throw_dice():
return random.randint(1,6)
def roll_and_show():
show_roll(throw_dice())
for i in range(3):
roll_and_show()
需要利用以上代码能打出骰子图像。谢谢各位大佬的帮助!!
|
|