This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Traceback (most recent call last): | |
| # File "<stdin>", line 1, in <module> | |
| # TypeError: func() got some positional-only arguments passed as keyword arguments: 'a, b' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def func(a, b, /, c): | |
| print(a, b, c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| items = [1, 2, 3, 4] | |
| print(len(items)) | |
| # 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| answer = random.choice(responses) | |
| print(f"The Magic 8 Ball says: {answer}") |
NewerOlder