Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a program that reads an age. If the age is or more, it shows You can vote. Otherwise it shows how many years are left.
Use >= when the value itself is included.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. Compare the age with 18, and use else for the other case.
age = int(input("How old are you? "))if age >= 18: shows You can vote.else: shows 18 - age, the years that are left.Check. For age , the program shows You can vote in 3 years. For age , it shows You can vote., because >= includes 18.
Log in to join the discussion.
Loading…