![見出し画像](https://assets.st-note.com/production/uploads/images/105401279/rectangle_large_type_2_4ffb1598a883fa4fd567de7c60f00ce3.png?width=1200)
Bardによるプログラミング学習01
問題1:円を描くプログラムを作成してください
Bardが使えるようになったのでさっそく使ってみた。事始めはChatGPTで行ったのと同じく、円を描くプログラムの作成です。
回答例1:はい、Python で円を描くプログラムです。
import turtle
# 画面の中央にカーソルを移動します
turtle.setpos(0, 0)
# 半径 100 の円を描きます
turtle.circle(100)
# プログラムを終了します
turtle.done()
模範解答という意味でしょうか、回答例として、Pythonのturtleモジュールを使って、コメント抜きでは4行のプログラムです。
![](https://assets.st-note.com/img/1683876822464-7POlv3DP9S.png?width=1200)
回答例2:はい、Python で円を描く簡単なプログラムを次に示します。
import turtle
turtle.shape("circle")
turtle.color("red")
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.forward(100)
turtle.done()
今回は赤い円も描いてくれましたのかな?
![](https://assets.st-note.com/img/1683879917658-RvJw59LXmD.png?width=1200)
Python
import turtle
turtle.shape("circle")
turtle.color("red")
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.circle(100)
turtle.done()
今回はちゃんとtirtle.circle(100)が書かれています。turtleの形、色、ペンアップ、ペンダウンが付け加わっています。
![](https://assets.st-note.com/img/1683880813006-1Dm6qKfh5k.png?width=1200)
回答例3:はい、Python で円を描く簡単なプログラムを次に示します。
import turtle
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.circle(100)
turtle.done()
回答例2のカメが特に指定されていませんね。
![](https://assets.st-note.com/img/1683882606769-QTFuIXyVyz.png?width=1200)
問題2:Pythonで赤い円を描きます。 ステージの大きさは800*600とします
ChatGPTで最初にこういう問題をやりました。比較のためにBardでも同じ問題をやってみます。
回答例0:ChatoGPTの場合
import turtle
# キャンバスの設定
turtle.setup(800, 600)
# 描画ペンの設定
pen = turtle.Turtle()
pen.pensize(5)
pen.pencolor("red")
# 円を描画
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.circle(100)
# 描画を終了
turtle.done()
![](https://assets.st-note.com/img/1683890236793-8uJLrP7wkh.png?width=1200)
回答例1:はい、Python で赤い円を描き、画面サイズを 800x600 に設定する簡単なプログラムを次に示します。
import turtle
turtle.shape("circle")
turtle.color("red")
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.circle(100)
turtle.screen.setup(800, 600)
turtle.done()
![](https://assets.st-note.com/img/1683883630211-jEK7U5UREY.png?width=1200)
また、AttributeError: module 'turtle' has no attribute 'screen'という警告が出ます。
回答例2:はい、Python で幅 800、高さ 600 のステージに赤い円を描く簡単なプログラムを次に示します。
mあた、m
turtle.screen.setup(width=800, height=600) の書き方が少し違っています。
同じく、AttributeError: module 'turtle' has no attribute 'screen'というエラーが出ます。
回答例3:承知しました。Python で半径が 100 の赤い円を画面の中央に描画するプログラムを次に示します。
import turtle
turtle.shape("circle")
turtle.color("red")
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.circle(100)
turtle.screensize(800, 600)
turtle.done()
これもturtle.screensize(800, 600)の書き方が違っています。今回はエラー表示はありません。
イメージしているのを描くには、どうも中身を塗りつぶすということを正確に言わないといけないのでしょうか。
問題3:円の中を赤く塗りつぶしてください
回答例1:はい、Python で半径が 100 の赤い円を画面の中央に描画し、円の中を赤く塗りつぶすプログラムを次に示します。
import turtle
turtle.shape("circle")
turtle.color("red")
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.circle(100)
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
turtle.screensize(800, 600)
turtle.done()
前のに影響されているのでしょうか。一度円を描いて、もう一度書いて塗りつぶしているようです。
![](https://assets.st-note.com/img/1683889238912-LHEBOHOFsj.png?width=1200)
感想
最初、Bardで円の模範解答を見て、三つの回答を準備してくれていると知り、これは素晴らしいと思ったけれど、必ずしもそうでもないかなという気がしてきた。また、応答結果がサーバーに残っているけれど、対話終了後は見えないというのも不便ですね。早急に改良してほしいと思います。
20230512記録