Problem: Whenever I run my code it always says “repl process died unexpectedly: signal: killed”
Function of Program: A Work-In-Progress Random Quote Generator
How do I fix this? Is it due to my computer or Repl itself?
LINK: https://replit.com/@Wenhan-Benjamin/Draft-Quote-Generator#main.py
Here is my code:
import time
print("Welcome to the Quote Generator!")
print("Enter a name (or 'done' to finish): ")
names = []
name = input()
while name != "done":
names.append(name)
time.sleep(1)
# Assign names to Person1, Person2, and Person3
Person1 = names[0] if len(names) > 0 else ""
Person2 = names[1] if len(names) > 1 else ""
Person3 = names[2] if len(names) > 2 else ""
# Print Quote
print(Person1 + ":", "*grinning*, Before you were what?"),
print(Person2 + ":", "Before I was-"),
print(Pe…
Hi @Wenhan-Benjamin , welcome to the forums! When I run your program, I put in some names, but when I put ‘done’ in, the code still does not continue.
Can you also format your code using ```
1 Like
By the way, your CPU and RAM usage is very high because you have a while loop which is checking that condition hundreds and thousands of times without stopping.
Thank you, I will try and use your suggestions.
To lower the RAM and CPU, import time
at the start of your code, and in the while loop, put in time.sleep(1)
Can you put the name=input( ) in the while loop, and put name=None above the while loop?
Certainly. Give me one second
print("Welcome to the Quote Generator!")
print("Enter a name (or 'done' to finish): ")
names = []
name = None
while name != "done":
name=input()
names.append(name)
time.sleep(1)
1 Like
It works now, thanks. Adding to this, I want to create a library to randomly generate a quote with the inputted names, is this possible?
Use the random library. Store the quotes in a list, and use random.choice(listOfQuotes)
to generate a random quote from the list.
To remove the chosen quote from the list, do this:
import random
chosenQuote=random.choice(listOfQuotes)
listOfQuotes.remove(chosenQuote)
Understood, I’ll try that. If we wanted to change the quote amount (num of people needed for quote), could we do that? Maybe using random.choice(listOfQuotes(appendNum)) ?
You have to set the number of quotes to generate (use a for loop).
1 Like
I see, any examples, I’ll like to try them
I will message you privately.
system
Closed
July 1, 2023, 8:49am
22
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.