Sharing positivity.
β ββA quote of the day utility picks a random quote from a 2D list of quotes and outputs it.
Write a program that stores quotes in a 2D array. The first index stores the quote and the second index stores the author. The program should output a random quote and the author.
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
random_quote that:You can use the following data:
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Martin Fowler
Code is like humour. When you have to explain it, itβs bad.
Cory House
Simplicity is the soul of efficiency.
Austin Freeman
The data structure for the first quote would be initialised as:
quote[0][0] = "Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
quote[0][1] = "Martin Fowler"
random_quote subprogram is called and the returned quote is stored in a list called quote."Simplicity is the soul of efficiency."
- Austin Freeman
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler
Restricted automated feedback
Automated feedback for this assignment is still under construction. Submitted programs are checked for syntax errors and their source code is checked for potential errors, bugs, stylistic issues, and suspicious constructs. However, no checks are performed yet to see if the program correctly implements the behaviour specified in the assignment.
# Quote of the day program
# -------------------------
# Import libraries
# -------------------------
---
import random
---
# -------------------------
# Subprograms
# -------------------------
---
# Function to output a random quote
---
def random_quote():
---
# Initialise data
quote = [["" for X in range(2)] for Y in range(3)]
---
quote[0][0] = "Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
quote[0][1] = "Martin Fowler"
quote[1][0] = "Code is like humour. When you have to explain it, itβs bad."
quote[1][1] = "Cory House"
quote[2][0] = "Simplicity is the soul of efficiency."
quote[2][1] = "Austin Freeman"
---
# Pick a random quote
index = random.randint(0, 2)
---
chosen_quote = [quote[index][0], quote[index][1]]
---
return chosen_quote
---
# -------------------------
# Main program
# -------------------------
random.seed()
---
quote = random_quote()
---
print(chr(34) + quote[0] + chr(34))
---
print(" -", quote[1])