Python Pioneers: A Beginner's Guide πŸ‡ͺπŸ‡Ή
8.64K subscribers
346 photos
40 videos
24 files
64 links
Welcome to Python Pioneers: Empowering Ethiopian students to embark on their coding journey.

πŸ“’ Channel: @python_pioneers
πŸ‘₯ Group: @python_pioneers_chat
Download Telegram
Media is too big
VIEW IN TELEGRAM
α‰΅αˆ‹αŠ•α‰΅ α‰£αˆαŠα‹ αˆ˜αˆ αˆ¨α‰΅ here is our simple number guessing game python code.

ሡለ codeኑ አሰራር ከሡር αŠ₯αŠ•αŒ½α‹αˆˆαŠ•...

#Game
#GuessGame

@python_pioneers
πŸ‘1
Number guessing game α‰ Python α‹­αˆ„αŠ• α‹­αˆ˜αˆ΅αˆ‹αˆα£ αŠ₯α‹«αŠ•α‹³αŠ•α‹±αŠ• የcodeαŠ‘αŠ• section αŠ₯αˆ΅α‰² αŠ₯αŠ•α‹­α£

1. Importing the random module:


   import random

- `random moduleαŠ• import α‹«αˆ¨αŒαŠα‹ set α‰£αˆ¨αŒαŠα‹ range αŒˆα‹°α‰₯ random ቁαŒ₯ር αŠ₯αŠ•α‹²αˆ°αŒ αŠ• αŠα‹α’

2. User Input for the Range:

   min = int(input("Minimum number for your guess range: "))
max = int(input("Maximum number for your guess range: "))

GameαŠ‘αŠ• α‹¨αˆšαŒ«α‹ˆα‰±α‹ αˆ°α‹ ለguessing range minimum αŠ₯αŠ“ maximum value αŠ₯αŠ•α‹²αˆ˜αˆ­αŒ₯ αŠ₯αŠ•αŒ α‹­α‰€α‹‹αˆˆαŠ•α’ αŠ¨α‹› α‹¨α‰°α‰€α‰ αˆαŠα‹αŠ• string data type int() function α‰ αˆ˜αŒ α‰€αˆ α‹ˆα‹° integerαŠα‰΅ αŠ₯αŠ•α‰€α‹­αˆ¨α‹‹αˆˆαŠ•α’


3. Generating a Random Number:

   rand_num = random.randint(min, max)

α‰ α‹šαˆ… section α‹°αŒαˆž random number generate αŠ₯αŠ•α‹²α‹«αˆ¨αŒαˆαŠ• import α‹«αˆ¨αŒαŠα‹αŠ• module α‰°αŒ α‰…αˆ˜αŠ“αˆ:
Using random.randint()

4. Initializing the Guess Counter:

   no_of_guesses = 0

αŠ₯α‹šαˆ… α‹°αŒαˆž userኑ αˆαŠ• α‹«αˆ…αˆ αŒŠα‹˜ αŠ₯αŠ•α‹°αŒˆαˆ˜α‰° α‹¨αˆαŠ•α‰†αŒ£αŒ αˆ­α‰ α‰΅αŠ• variable declare αŠ αˆ­αŒˆαŠ“αˆα£ initial value α‹°αŒαˆž zero ሰαŒ₯α‰°αŠ•α‹‹αˆα’

#GuessGame

@python_pioneers
while True:
user_guess = int(input("Make a guess: "))
if user_guess == rand_num:
print("Congrats, you got the number!")
break
elif user_guess > max or user_guess < min:
print("Your guess is out of range!")
break
elif user_guess > rand_num:
print("You are above the number, make a lower guess.")
elif user_guess < rand_num:
print("You are below the number, make a higher guess.")
else:
print("Wrong Input!")
break
no_of_guesses += 1

- The program enters an infinite loop using while True: where the user is repeatedly prompted to guess the number.

- Checking if the Guess is Correct:
Userኑ α‹«αˆ΅αŒˆα‰£α‹ ቁαŒ₯ር ከ random numberኑ αŒ‹αˆ­ αŠ₯ኩል αŠ¨αˆ†αŠ "Congrats, ..." α‹¨αˆšαˆˆα‹ message printed α‹­αˆ†αŠ“αˆα’

- Checking for Out-of-Range Guesses:
Userኑ α‹«αˆ΅αŒˆα‰£α‹ ቁαŒ₯ር specified αŠ¨αˆ†αŠα‹ range ውαŒͺ αŠ¨αˆ†αŠ loopኑ α‹­α‰†αˆ›αˆα’


- Providing Hints:

- If the guess is higher than the random number, the user is informed and asked to guess a lower number.

- If the guess is lower than the random number, the user is informed and asked to guess a higher number.



- Incrementing the Guess Counter:

After each guess, the no_of_guesses counter is incremented by 1 to track the number of attempts.

#GuessGame

@python_pioneers
πŸ‘3⚑1πŸ™1