Skip to content

Instantly share code, notes, and snippets.

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

Exercise 1

Teacher solution

age1 = int(input("Enter the age of the first person: "))
age2 = int(input("Enter the age of the second person: "))

if age1 < age2:
  print("The first person is younger.")
elif age2 < age1:
  print("The second person is younger.")
else:
  print("Both people are the same age.")

Exercise 2

Teacher solution

char = input('Enter a character: ')

if char >= 'a' and char <= 'z':
    print('The letter', char, 'is lowercase')
elif char >= 'A' and char <= 'Z':
    print('The letter', char, 'is uppercase')
elif char >= '0' and char <= '9':
    print(char, 'is a number')
else:
    print(char, 'is a symbol')

# More Pythonic alternative
if 'a' <= char <= 'z':
    print('The letter', char, 'is lowercase')
elif 'A' <= char <= 'Z':
    print('The letter', char, 'is uppercase')
elif '0' <= char <= '9':
    print(char, 'is a number')
else:
    print(char, 'is a symbol')

Exercise 3

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment