Jayaram18 / Jayaram18/python-random-quote

Read from a file

Aperta
#3 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
0
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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!

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Segui l'esempio Python dell'issue, usando quotes.txt come file di input. Esegui il programma e verifica che stampi solo la prima citazione; quindi incolla quella citazione come commento, come richiesto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
cli
Tipo di issue
Funzionalità
Difficoltà
1/5
Tempo stimato
Meno di un'ora
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.