Skip to content

Instantly share code, notes, and snippets.

@miquelvir
Created March 16, 2025 22:22
Show Gist options
  • Save miquelvir/165414abf858ba59164bc04e9991fc38 to your computer and use it in GitHub Desktop.
Save miquelvir/165414abf858ba59164bc04e9991fc38 to your computer and use it in GitHub Desktop.
devQuest - 16/03/2025 23:21

Exercise 1

Teacher solution

year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
  print("The year", year, "is a leap year")
else:
  print("The year "+str(year)+" is not a leap year")  # another way to format a message with variables

Exercise 2

Teacher solution

num = int(input("Enter a number: "))

while num > 0:    # while, we will ask for factorials
  factorial = 1
  while num > 0:  # calculate the factorial
    factorial *= num
    num -= 1
  print(factorial)
  num = int(input("Enter a number: "))

print("Bye")

Exercise 3

Teacher solution

# Version with ord() and chr()
character = ord(input("Enter a character (will crash if you enter more than one)"))

if ord('a') <= character <= ord('z'):
    print('The letter', chr(character), 'is lowercase')
elif ord('A') <= character <= ord('Z'):
    print('The letter', chr(character), 'is uppercase')
elif ord('0') <= character <= ord('9'):
    print(chr(character), 'is a number')
else:
    print(chr(character), 'is a symbol')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment