Skip to content

Instantly share code, notes, and snippets.

@logankilpatrick
Last active January 3, 2022 12:47
Show Gist options
  • Save logankilpatrick/cc31ea86b28c588e49aec0f9b5989a6c to your computer and use it in GitHub Desktop.
Save logankilpatrick/cc31ea86b28c588e49aec0f9b5989a6c to your computer and use it in GitHub Desktop.
# Number Guessing Game in Julia
# Source: https://github.com/logankilpatrick/10-Julia-Projects-for-Beginners
function play_number_guess_human()
total_numbers = 25 #
# Generate a random number within a certain range
target_number = rand(1:total_numbers)
guess = 0
# While the number has not been guessed, keep prompting for guesses
while guess != target_number
print("Please guess a number between 1 and $total_numbers: ")
guess = parse(Int64, readline())
# Convert the string value input to a number
# If we are within +/-2 of the target, give a hint
if abs(target_number - guess) <= 2 && target_number != guess
print("\nYou are getting closer!\n")
end
end
print("Nice job, you got it!")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment