def函数,循环
问题: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 =
roll_im = roll_images
img = Image.open(BytesIO(roll_im.content))
def show_roll(num):
【
img.thumbnail()
display(img)
】
for n in image:
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()
需要利用以上代码能打出骰子图像。谢谢各位大佬的帮助!!
页:
[1]