![](https://blogimg.goo.ne.jp/user_image/00/c2/9210f00196c8f8e23e3a9a231530106c.jpg)
任意のPythonコードをQRコード化するPythonプログラムを書いて
import qrcode
def generate_qrcode(data, filename):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
image = qr.make_image(fill_color="black", back_color="white")
image.save(filename)
# QRコード化したいPythonコード
python_code = '''
import math
def calculate_area(radius):
return math.pi * radius ** 2
r = float(input("Enter the radius: "))
area = calculate_area(r)
print("The area of the circle is:", area)
'''
# QRコードを生成して保存
generate_qrcode(python_code, 'python_code_qr.png')
![](https://blogimg.goo.ne.jp/user_image/40/5d/742739529a0977ea698acaeee190df2d.jpg?1684346996)