Skip to content

Instantly share code, notes, and snippets.

@davidmerwin
Last active November 22, 2023 03:48
Show Gist options
  • Save davidmerwin/134ed1f6d6de4f9687b7a23cb2b8dff6 to your computer and use it in GitHub Desktop.
Save davidmerwin/134ed1f6d6de4f9687b7a23cb2b8dff6 to your computer and use it in GitHub Desktop.
This code asks the user to guess a number between 1 and 10, then prints an error message if it fails.

Matrix Brew Guessing Game

Preview:
import numpy as np
import random

def main():
    global guess
    guess = 0
    print('Welcome to the Matrix Brew Guessing Game!')
    while guess != 7:
        guess = int(input('Guess a number between 1 and 10: '))
        if guess < 7:
            print('Too low! Try again.')
        elif guess > 7:
            print('Too high! Try again.')
        else:
            print('Congratulations! You guessed the correct number!')


if __name__ == '__main__':
    main()
Associated Context
Type Code Snippet ( .py )
Associated Tags Numpy Library Random Data Structure Matrix Brew Guessing Game Input Function Conditional Statements Python Programming Number Comparison Console Output Error Handling
💡 Smart Description This code asks the user to guess a number between 1 and 10, then prints an error message if it fails.
This code snippet is a simple guessing game where the user is prompted to guess a number between 1 and 10. The program provides feedback if the guess is too low or too high, and congratulates the user when they guess the correct number,
🔎 Suggested Searches Matrix Brew Guessing Game
How to guess a number between 1 and 10 in Matplotlib
Matrix Brew programming with random numbers
Handling problems matrix Brew using Python
Programmatically calculating the correct number
Python code for guessing game with number between 1 and 10
Python code for guessing game with while loop
Python code for guessing game with user input
Python code for guessing game with if-else statements
Python code for guessing game with global variable
Related Links https://www.w3schools.com/python/numpy/numpy_creating_arrays.asp
https://www.w3schools.com/python/python_operators.asp
https://www.w3schools.com/python/python_lists.asp
https://python-course.eu/numerical-programming/overview-of-matplotlib.php
https://www.machinelearningplus.com/plots/matplotlib-tutorial-complete-guide-python-plot-examples/
https://plotly.com/python/
https://www.geeksforgeeks.org/random-numbers-in-python/
https://docs.python.org/3/library/random.html
https://www.w3schools.com/python/ref_random_randint.asp
https://www.datacamp.com/tutorial/numpy-random
https://realpython.com/python-random/
https://www.programiz.com/python-programming/methods/built-in/int
https://github.com/davidmerwin
Related People Jack Cheng, David Merwin, David Jeffrey Merwin
Sensitive Information No Sensitive Information Detected
Shareable Link https://davidmerwin.pieces.cloud/?p=20c94f8ba9
@davidmerwin
Copy link
Author

import numpy as np
import random

def main():
global guess
guess = 0
print('Welcome to the Matrix Brew Guessing Game!')
while guess != 7:
guess = int(input('Guess a number between 1 and 10: '))
if guess < 7:
print('Too low! Try again.')
elif guess > 7:
print('Too high! Try again.')
else:
print('Congratulations! You guessed the correct number!')

if name == 'main':
main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment