# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
# Level 1
# 1. Driving eligibility
age = int(input("Enter your age: "))
if age >= 18:
print("You are old enough to learn to drive.")
else:
print(f"You need {18 - age} more years to learn to drive.")
# 2. Age comparison
my_age = 25
your_age = int(input("Enter your age: "))
if your_age > my_age:
diff = your_age - my_age
year_word = "year" if diff == 1 else "years"
print(f"You are {diff} {year_word} older than me.")
elif your_age < my_age:
diff = my_age - your_age
year_word = "year" if diff == 1 else "years"
print(f"I am {diff} {year_word} older than you.")
else:
print("We are the same age.")
# 3. Compare two numbers
a = int(input("Enter number one: "))
b = int(input("Enter number two: "))
if a > b:
print(f"{a} is greater than {b}")
elif a < b:
print(f"{a} is smaller than {b}")
else:
print(f"{a} is equal to {b}")
# Level 2
# 4. Grading system
score = int(input("Enter your score: "))
if 80 <= score <= 100:
print("Grade: A")
elif 70 <= score <= 89:
print("Grade: B")
elif 60 <= score <= 69:
print("Grade: C")
elif 50 <= score <= 59:
print("Grade: D")
elif 0 <= score <= 49:
print("Grade: F")
else:
print("Invalid score")
# 5. Season checker
month = input("Enter the month: ").strip().lower()
if month in ['september', 'october', 'november']:
print("The season is Autumn")
elif month in ['december', 'january', 'february']:
print("The season is Winter")
elif month in ['march', 'april', 'may']:
print("The season is Spring")
elif month in ['june', 'july', 'august']:
print("The season is Summer")
else:
print("Invalid month")
# 6. Fruit checker
fruits = ['banana', 'orange', 'mango', 'lemon']
new_fruit = input("Enter a fruit: ").lower()
if new_fruit in fruits:
print("That fruit already exists in the list")
else:
fruits.append(new_fruit)
print("Updated fruits list:", fruits)
# Level 3
# 7. Person dictionary and skill checking
person = {
'first_name': 'Asabeneh',
'last_name': 'Yetayeh',
'age': 250,
'country': 'Finland',
'is_marred': True,
'skills': ['JavaScript', 'React', 'Node', 'MongoDB', 'Python'],
'address': {
'street': 'Space street',
'zipcode': '02210'
}
}
# a. Check for middle skill
if 'skills' in person:
skills = person['skills']
middle_index = len(skills) // 2
print("Middle skill:", skills[middle_index])
# b. Check if Python exists
if 'skills' in person:
print("Has Python skill:", 'Python' in person['skills'])
# c. Developer title check
if 'skills' in person:
skills = person['skills']
if set(skills) == {'JavaScript', 'React'}:
print("He is a front end developer")
elif {'Node', 'Python', 'MongoDB'}.issubset(skills):
print("He is a backend developer")
elif {'React', 'Node', 'MongoDB'}.issubset(skills):
print("He is a fullstack developer")
else:
print("Unknown title")
# d. Married and lives in Finland
if person['is_marred'] and person['country'] == 'Finland':
print(f"{person['first_name']} {person['last_name']} lives in {person['country']}. He is married.")