Skip to content

Instantly share code, notes, and snippets.

View bsoyka's full-sized avatar

Ben Soyka bsoyka

View GitHub Profile
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: func() got some positional-only arguments passed as keyword arguments: 'a, b'
def func(a, b, /, c):
print(a, b, c)
items = [1, 2, 3, 4]
print(len(items))
# 4
items = [1, 2, 3, 4]
print(len(obj=items))
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: len() takes no keyword arguments
C:/Users/username/Desktop>python main.py
Tell the Magic 8 Ball your question: Will my life be filled with joy?
The Magic 8 Ball says: Signs point to yes
C:/Users/username/Desktop>
import random
responses = [
"It is certain",
"Without a doubt",
"You may rely on it",
"Yes definitely",
"It is decidedly so",
"As I see it, yes",
"Most likely",
import random
responses = [
"It is certain",
"Without a doubt",
"You may rely on it",
"Yes definitely",
"It is decidedly so",
"As I see it, yes",
"Most likely",
# This will get the input, make it all lowercase, and save it in the 'question' variable.
question = input("Tell the Magic 8 Ball your question: ").lower()
# This will check if the words "meaning of life" are in the question.
if "meaning of life" in question:
#This will respond with the meaning of life.
print("The Magic 8 Ball says: 42")
else:
while True:
answer = random.choice(responses)
print(f"The Magic 8 Ball says: {answer}")