Session 03 - Python for Forensics
The code here is to support the Session 03 lecture.
guessingGame.py
import random
def main():
print("Hello! What is your name?")
userName = input()
print(f"Well, {userName}, I am thinking of a number between 1 and 20!")
secretNumber = random.randint(1, 20)
attempts = 0
while attempts < 6:
print("Take a guess:")
userGuess = int(input())
attempts += 1
if userGuess < secretNumber:
print("Too Low!!")
elif userGuess > secretNumber:
print("Too High!!")
else:
print(f"Good Job! It took you {attempts} attempts to guess the number.")
break
if userGuess != secretNumber:
print(f"Sorry, {userName}. The number I was thinking of was {secretNumber}.")
if __name__ == "__main__":
main()