feat: created several scratch example files for loops and conditionals

This commit is contained in:
baphim
2026-09-30 14:34:44 -04:00
parent 1e740c7ff8
commit 605ab16b9c
3 changed files with 81 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# # Defines 'name' var as user input
# name = input('What is your name? ')
# # Print welcome string formatted to repeat user input
# print(f'Hello {name}')
# import 'random' module, built-in module that creates random numbers
import random
# Define 'secret_number' var as a randomly assigned integer between 1 and 10
secret_number = random.randint(1, 10)
# Print starting message
print('I am thinking of a number between 1 and 10')
while True:
# Sets 'guess' var to user input converted to integer
guess = int(input('Take a guess: '))
# if 'guess' equals 'secret_number', prints congrats message and breaks loop
if guess == secret_number:
print('Congrats! You guessed it!')
break
# If 'guess' is less than 'secret_number', print try again message
elif guess < secret_number:
print('Too low, try again.')
# If no other conditions are true, print try again message
else:
print('Too high, try again.')