Jayaram18 / Jayaram18/python-random-quote

Read from a file

オープン
#3 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
0
フォーク
0
PR マージ指標
30日以内にマージされた PR はありません

説明

Now we're ready to really build our quote bot. To test things out, we'll read all the quotes from a file and print the first one.

First, you can remove our test quote, the print statement on line 2. You can either comment it out by adding a `#` at the start of the line, or remove it completely.

Next, remove the other comments by deleting `#` from the start of the other four lines to get Python code like this:

```
f = open("quotes.txt")
quotes = f.readlines()
f.close()

print(quotes)
```

Here we are opening the `quotes.txt` file, reading all the lines into a new _variable_ called `quotes`, then closing the file (defined by the variable `f`). Finally, we print out the quotes.

You can run this code and we'll get a dump of _all_ the quotes in the quotes file. That's because Python stored them all in an _array_, which is a single variable that holds a list of values.

## Print the first element of an array

Since we only want one quote, we need to edit our code to print only the first value in the `quotes` array.

In your code, find the print line and add this special modifier `[0]` so that the line now reads:
` print(quotes[0])`

The square brackets tell Python that we want a specific item in the array. Since it starts counting at zero, we've grabbed the first item.

## Comment with the first quote

Run your code and copy the value to your clipboard.

Paste the quote as a comment here and I'll follow up with next steps!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Issue の Python の例に従い、入力ファイルとして quotes.txt を使用してください。プログラムを実行して、最初の引用だけが出力されることを確認し、その引用を指示どおりコメントとして貼り付けてください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
cli
issue の種類
機能追加
難易度
1/5
見積もり時間
1時間未満
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。