(HELP)(Python) Edhesive: 7.5 code practice: Question 2
Instructions
In the file KnockKnock.txt
(Links to an external site.)
, the odd lines have the answers to, "Who’s there?', and the even numbers have the answers to, "_________ who?" question.
Count the number of lines in the file, then generate a random knock-knock joke from the file.
Answers
Answered by
0
Answer:
that is the best questions ever
Answered by
0
Answer:
import random
file = open("Knock.txt")
lines = file.readlines()
count = str(len(lines))
n = random(0,count)
for n in lines:
print(lines.n)
Explanation:
Let's consider the content of "Knock.txt" as per below,
" Nobel
No bell, that's why I knocked!
Boo
I didn't mean to make you cry! It's just me!
Will
Will you let me in? It's freezing out here!
Barbie
Barbie Q Chicken!
Figs
Figs the doorbell, it's broken!
Kiwi
Kiwi go to the store?
Lettuce
Lettuce in, we're freezing!
Olive
Olive right next door to you.
Turnip
Turnip the volume, it's quiet in here.
Ice cream
Ice cream if you don't let me in! "
The above program will generator random number and print the line as expected.
Similar questions