age = 15
citisenship = True
if citisenship and age >= 18:
#this works when citizenship is true and your age is greater than or equal to 18
print("You can vote")
else:
print("You can't vote")
# if you aren't a citizen or you aren't over 18, then you can't vote
#ask for the users test score
testScore = int(input("Please enter your test score: "))
# using the inputted grade, find what letter grade they get
grade = ""
if testScore < 25:
grade = "F"
elif testScore >= 25 and testScore <= 45:
grade = "E"
elif testScore > 45 and testScore <= 50:
grade = "D"
elif testScore > 50 and testScore <= 60:
grade = "C"
elif testScore > 60 and testScore <= 80:
grade = "B"
else:
grade = "A"
# print the letter grade they got
print("Your grade is:", grade)
def calculate_updated_salary(currentSalary, yos):
if yos > 5:
newSalary = currentSalary * 1.05
# the salary goes up by 5% if worked more than 5 years
return newSalary
else:
return currentSalary # keep the salary if you worked less than 5 years
# get the salary from the user
currentSalary = float(input("Enter your current salary: "))
# get the number of years they have worked
yos = int(input("Enter the number of years you have serviced the company: "))
# find the updated salary
newSalary = calculate_updated_salary(currentSalary, yos)
# see if the salary updated and print the respective message
if newSalary != currentSalary:
print("Your updated salary is: $" + str(newSalary))
else:
print("No change in your salary. Your current salary is: $" + str(currentSalary))
def fibonacci(x):
if x==1:
return(0) # First terminating statement
if x == 2:
return(1) # Second terminating statement
else:
return(fibonacci(x-1)+ fibonacci(x-2))
for i in range(8):
print(fibonacci(i+1))
It needs two variables because it needs to store two variables at a time. It needs the previous two variables to add.