0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

アプリ開発100本ノックDay 4: 円周率チェッカー - あなたの誕生日、円周率に隠れてる?🔍

Posted at

100個のアプリ作るぞ!生成AIと一緒の大冒険🎉 -

ミッション: 4桁の数字を入力すると、それが円周率の何桁目に出現するのか教えてくれるアプリを作る!

開発ストーリー:

円周率って、無限に続く数字じゃないですか…🤔 そこに自分の誕生日とか、好きな数字とかが含まれてたら、なんかロマンチックじゃないですか?💖 ということで、4桁の数字を入力すると、それが円周率の何桁目にあるのか教えてくれるアプリを作ってみました!✨ 円周率のデータはテキストファイルで用意して、Pythonで検索するシンプルな仕組みです。

コードはこちら! (Python):

from flask import Flask, render_template, request

app = Flask(__name__, template_folder='pi')

with open("pi.txt","r") as f:
    pi = f.read().replace(".", "")

@app.route("/", methods=["GET", "POST"])
def index():
    # 以下略 (コードは前と同じ)

if __name__ == "__main__":
    app.run(debug=True, port=5006)
Use code with caution.
Markdown
HTMLで結果を表示:
<!DOCTYPE html>
<html>
<head>
    <title>円周率検索</title>
</head>
<body>
    <h1>4桁の数字を入力してください</h1>
    <form method="post">
        <input type="text" name="number" value="{{ input_number }}" maxlength="4">
        <button type="submit">検索</button>
    </form>

    {% if position != -1 %}
        <p>{{ input_number }}円周率の小数点以下{{ position }}桁目にあります</p>
    {% elif input_number != "" %}
        <p>{{ input_number }}は見つかりませんでした</p>
    {% endif %}
</body>
</html>


工夫ポイント:
円周率のデータはテキストファイルで管理
FlaskでWebアプリ化
HTMLで結果を見やすく表示

今日の学び:
円周率って奥が深い…🤔
ファイル読み込み意外と簡単!👍
文字列検索便利!✨
未来への野望:
もっと桁数を増やしたい (自分の電話番号とかも検索できるように!📞)
検索速度をもっと速くしたい!🚀
見つかった位置を円周率のビジュアライザーで表示できたら面白そう!👀
100個アプリ開発の旅順調に進んでます!😄 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?