├── .github └── FUNDING.yml ├── README.md └── main.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [kying18] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # guess-the-number 2 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def guess(x): 4 | random_number = random.randint(1, x) 5 | guess = 0 6 | while guess != random_number: 7 | guess = int(input(f'Guess a number between 1 and {x}: ')) 8 | if guess < random_number: 9 | print('Sorry, guess again. Too low.') 10 | elif guess > random_number: 11 | print('Sorry, guess again. Too high.') 12 | 13 | print(f'Yay, congrats. You have guessed the number {random_number} correctly!!') 14 | 15 | def computer_guess(x): 16 | low = 1 17 | high = x 18 | feedback = '' 19 | while feedback != 'c': 20 | if low != high: 21 | guess = random.randint(low, high) 22 | else: 23 | guess = low # could also be high b/c low = high 24 | feedback = input(f'Is {guess} too high (H), too low (L), or correct (C)?? ').lower() 25 | if feedback == 'h': 26 | high = guess - 1 27 | elif feedback == 'l': 28 | low = guess + 1 29 | 30 | print(f'Yay! The computer guessed your number, {guess}, correctly!') 31 | 32 | 33 | guess(10) --------------------------------------------------------------------------------