nighthawkcoders / teacher

Jupyter Notebooks and Posts dedicated to learning Python
MIT License
0 stars 63 forks source link

3.5 Boolean Expressions and 3.6 Conditionals | Compci Blogs #24

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

3.5 Boolean Expressions and 3.6 Conditionals | Compci Blogs

3.5 Boolean Expressions and 3.6 Conditionals

https://nighthawkcoders.github.io/teacher/2023/10/09/P1_Booleans_IPYNB2.html

tarunja1ks commented 1 year ago

https://tarunja1ks.github.io/student//2022/10/10/booleanteamteach_IPYNB_2_.html

monke7769 commented 1 year ago

https://monke7769.github.io/copy1/3536

alishahussain commented 1 year ago

https://alishahussain.github.io/student2//2023/10/11/boolean_conditionals_IPYNB_2_.html

SriS126 commented 1 year ago

https://sris126.github.io/student//2023/09/08/BooleanExpressionalsandCondtionalsHW_IPYNB_2_.html

tanvim-18 commented 1 year ago
  1. age = 17 if age <= 18: print("you can't vote ") else: print("you can vote")

  2. salary = float(input("Enter your salary: ")) years_of_service = int(input("Enter your years of service: "))

if years_of_service > 5: bonus_percentage = 5 # 5% bonus bonus_amount = (bonus_percentage / 100) * salary print(f"Congratulations! You are eligible for a {bonus_percentage}% bonus.") print(f"Your bonus amount is: ${bonus_amount:.2f}") else: print("Sorry, you are not eligible for a bonus.")

  1. marks = float(input("Enter your marks: "))

if marks < 25: grade = "F" elif marks >= 25 and marks < 45: grade = "E" elif marks >= 45 and marks < 50: grade = "D" elif marks >= 50 and marks < 60: grade = "C" elif marks >= 60 and marks <= 80: grade = "B" else: grade = "A"

print(f"Your grade is: {grade}")

DavidL0914 commented 1 year ago

Homework 1

Function to check if you are eligible to vote.

def votecheck(age): if age >= 18:

If you are older than 18, then you are eligible to vote.

    print("You are eligible to vote.")
else:
    # If you are younger than 18, then you are not eligible to vote.
    print("You are not eligible to vote.")

Takes input of the user's age and converts it to an integer.

age = input("Please enter your age: ") age = int(age) votecheck(age)

Homework 2

Function to check if the person has a bonus and calculate how much of a bonus there is.

def bonuscheck(salary, years): if years > 5:

If the person has been at the company for more than 5 years, there is a 5% bonus.

    bonus = salary * 0.05
    print("Net Bonus:", bonus, "dollars")
else:
    # If the person has been at the company for less than 5 years, there is no bonus.
    print("Net Bonus: 0 dollars")

Takes the input of the number of years and the salary.

years = input("How many years have you been in the company: ") years = float(years) salary = input("What is your annual salary: ") salary = float(salary) bonuscheck(salary, years)

Homework 3

Function to print out the grade that a person has earned.

def gradecheck(score):

For checks if the score is an F and slowly moves up until it gets to A.

if score < 25:
    print("F")
elif score >= 25 and score < 45:
    print("E")
elif score >= 45 and score < 50:
    print("D")
elif score >= 50 and score < 60:
    print("C")
elif score >= 60 and score < 80:
    print("B")
elif score >= 80:
    print("A")

Takes an input that is the person's score and runs the function gradecheck.

score = input("Please enter your score: ") score = float(score) gradecheck(score)

abby-albert commented 1 year ago

1:

citizen = input("Are you a citizen? (yes/no): ").lower() age = int(input("Enter your age: ")) if citizen == "yes" and age >= 18: print("You are eligible to vote.") else: print("You are not eligible to vote.")

2:

salary = float(input("Enter your salary: $")) years_of_service = int(input("Enter your years of service: ")) if years_of_service > 5: bonus = 0.05 * salary print(f"You are eligible for a bonus of ${bonus:.2f}.") else: print("You are not eligible for a bonus.") net_bonus = 0 if years_of_service <= 5 else bonus print(f"Net Bonus Amount: ${net_bonus:.2f}")

3:

marks = float(input("Enter your marks: ")) if marks < 25: grade = "F" elif 25 <= marks < 45: grade = "E" elif 45 <= marks < 50: grade = "D" elif 50 <= marks < 60: grade = "C" elif 60 <= marks < 80: grade = "B" else: grade = "A" print(f"Your grade is: {grade}")

alaraipek commented 1 year ago

https://alaraipek.github.io/student//2023/10/12/boolean_IPYNB_2_.html