nighthawkcoders / teacher

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

P1 booleans and conditions | Compci Blogs #32

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

P1 booleans and conditions | Compci Blogs

3.5 Boolean Expressions and 3.6 Conditionals

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

Nupurbb commented 1 year ago

Problem 1: Voter Eligibility

Ask the user for their citizenship status and age.

is_citizen = input("Are you a citizen? (yes/no): ").strip().lower() age = int(input("Enter your age: "))

Check if the user is a citizen and 18 or older.

if is_citizen == "yes" and age >= 18: print("You are eligible to vote.") else: print("You are not eligible to vote.")

Problem 2: Employee Bonus

Ask the user for their salary and years of service.

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

Check if the employee's years of service is more than 5 to give a 5% bonus.

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.")

Problem 3: Grading System

Ask the user to enter marks.

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

Determine the corresponding grade based on the rules.

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}")

tarunja1ks commented 1 year ago

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

tarasehdave commented 1 year ago

https://tarasehdave.github.io//c4.1/2023/10/10/BooleansTT_IPYNB_2_.html

devaSas1 commented 1 year ago

Homework 1

citizen = False age = 24 if citizen and age >=18:# if both conditions are met print("you are eligible to vote") else: print("You are not eligible to vote")#if either condition isnt met

Homework 2

salary = int(input())#user input years = int(input())#user input if years >= 5:#checks if service is above 5 years salary = salary*1.05 #adds 5% bonus print("Your salary is now", salary) else: print("no bonus")

Homework 3

grade = int(input()) if grade<25: print("F") if 25<=grade<45: print("E") if 45<=grade<50: print("D") if 50<=grade<60: print("C") if 60<=grade<80: print("B") if grade>=80: print("A")

shuban-789 commented 1 year ago

Problem 1

ask for age

n = int(input("enter age: "))

main logic

if n >= 18:

print this only if age is 18 or above

print("You are eligible to vote!")

else:

print this only if age is less than 18

print("You are NOT eligible to vote!")

Problem 2

ask for years of service

salary = int(input("salary? ")) years = int(input("You many years of service? "))

main logic: give bonus only if years of service is above 5

if years > 5: print("total bonus: "+str(salary*1.05)) else: print("no bonus lol")

Problem 3

Grade logic

n = int(input("Enter grade: ")) if n < 25: print("F") if 45 > n >= 25: print("E") if 50 > n >= 45: print("D") if 60 > n >= 50: print("C") if 80 > n >= 60: print("B") if n >= 80: print("A")

TejM123 commented 1 year ago

https://tejm123.github.io/student//5.a/c4.1/2023/10/16/lesson4HW_IPYNB_2_.html

Djxnxnx commented 1 year ago

https://djxnxnx.github.io/student//5.a/c4.1/2023/10/16/homework-3_IPYNB_2_.html

alishahussain commented 1 year ago

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

alishahussain commented 1 year ago

ignore ^^ real submission: https://alishahussain.github.io/student2//2023/10/11/boolean_conditionals_IPYNB_2_.html

Sreejarai123 commented 1 year ago

1:

Get user input for citizenship status and age

citizen_status = input("Are you a citizen? (yes/no): ").lower() age = int(input("Enter your age: "))

Check if the user is a citizen and 18 or older

is_citizen = citizen_status == "yes" is_18_or_older = age >= 18

Use boolean logic to determine eligibility

is_eligible_to_vote = is_citizen and is_18_or_older

Display the result

if is_eligible_to_vote: print("You are eligible to vote. Go ahead and cast your vote!") else: print("Sorry, you are not eligible to vote. Please wait until you meet the criteria.")

2:

Get user input for salary and years of service

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

Check if the employee is eligible for a bonus (more than 5 years of service)

is_eligible_for_bonus = years_of_service > 5

Calculate the bonus amount (5% of salary) if eligible

if is_eligible_for_bonus: bonus_percentage = 5 bonus_amount = (bonus_percentage / 100) * salary print(f"Congratulations! You are eligible for a {bonus_percentage}% bonus.") print(f"Net bonus amount: ${bonus_amount:.2f}") else: print("Sorry, you are not eligible for a bonus at this time.")

3:

Get user input for marks

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

Determine the grade based on the given rules

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"

Display the corresponding grade

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

peytonl11098 commented 1 year ago

Problem 1

citizen = input("Are you a US citizen? (yes/no)")

if yes, they need to be 18 or older

if citizen == "yes": age = int(input("what is your age")) if age >= 18:

if they are 18 or older, they can vote

    print("you are eligible to vote!")
else:
    #if not, they can't vote
    print("sorry, you are too young to vote. maybe wait a few years!")

else:

if they are not a citizen, they also can't vote

print("sorry, you are not eligible to vote")

Problem 2

current_salary=float(input("Type your salary")) years=int(input("Type the amount of years you have serviced the company")) if(years>5): print(current_salary*1.05, "is your new salary") else: print(current_salary, "is your salary")

Problem 3

user input

marks = float(input("What are your marks?"))

all the grade rules

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 the grade

print("Your grade is a(n)", grade)

aidenk1 commented 1 year ago

Question 1

age = 16 if (age >= 18) == True: print("You can vote") else: print("You cannot drive")

Question 2

yearsInCompany = int(input("How long have you been with the company?: ")) salary = int(input("Enter your salary: ")) bonus = 0 if yearsInCompany >= 5: bonus = (int(salary) * 1.05) - salary print("Your bonus is " + "$" + str(bonus)) else: print("Sorry, no bonus.")

Question 3

grade = int(input("Enter your grade")) if grade > 80: letterGrade = "A" elif grade > 60: letterGrade = "B" elif grade > 50: letterGrade = "C" elif grade > 45: letterGrade = "D" elif grade > 25: letterGrade = "E" else: letterGrade = "F" print(letterGrade)

monke7769 commented 1 year ago

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

AustinZhang1 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)

DavidL0914 commented 1 year ago

Problem 1: Voting Eligibility

Get user input for age

age = int(input("Enter your age: "))

Check eligibility using boolean logic

if age >= 18: print("You are eligible to vote.") else: print("You are not eligible to vote.")

Problem 2: Employee Bonus

Get user input for salary and years of service

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

Calculate bonus

if years_of_service > 5: bonus = 0.05 * salary print(f"Your bonus amount is ${bonus:.2f}") else: print("You are not eligible for a bonus.")

Problem 3: Grading System

Get user input for marks

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

Determine the grade based on the grading system

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 the corresponding grade

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

Tanuj253 commented 1 year ago

The comment didnt go through for some reason: https://tanuj253.github.io/student/5.a/c4.1/2023/10/10/boolean-expression-and-conditions_IPYNB_2_.html

SriS126 commented 1 year ago

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

AidanLau10 commented 1 year ago

https://aidanlau10.github.io/student//2023/10/10/3.5-3.6_IPYNB_2_.html

RayyanDarugar commented 1 year ago

https://rayyandarugar.github.io/student//c7.0/2023/10/19/BooleansHack_IPYNB_2_.html

spooketti commented 1 year ago

problem 1

user = int(input()) #user input as integer (age)
if user >= 18: #>= checks if they are older than or equal to 18
    print("vote eligible")
else: #otherwise
    print("user is unable to vote")t

problem 2

import datetime

today = datetime.date.today()

year = int(today.year)

salary = int(input("What is your salary"))
servyear = int(input("What year did you start"))
if year - servyear > 5:
    salary = salary + (salary * .05)
print(salary)

problem 3

grade = int(input("enter your grades"))

def detGrade():
    if grade < 25:
        return "F"
    if grade < 45:
        return "E"
    if grade < 50:
        return "D"
    if grade < 60:
        return "C"
    if grade < 80:
        return "B"
    if grade > 80:
        return "A"

print(detGrade())

jonathan liu

Nathaniel633 commented 1 year ago

https://github.com/Nathaniel633/student/blob/main/_notebooks/2023-10-17-bullying.ipynb

sharonkodali commented 1 year ago

https://sharonkodali.github.io/sharonk//2023/10/21/bool-cond-hw_IPYNB_2_.html

ChrisP121 commented 1 year ago

1.

is_citizen = input("Are you a citizen? (yes/no): ").strip().lower() == "yes" age = int(input("Enter your age: "))

if is_citizen 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 the number of years in service: "))

if years_of_service > 5: bonus = 0.05 * salary # 5% bonus print(f"Your bonus amount is: ${bonus:.2f}") else: print("You are not eligible for a bonus.") 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}")

abby-albert commented 1 year ago

1

is_citizen = input("Are you a citizen? (yes/no): ").strip().lower() == "yes" age = int(input("Enter your age: "))

if is_citizen 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 the number of years in service: "))

if years_of_service > 5: bonus = 0.05 * salary # 5% bonus print(f"Your bonus amount is: ${bonus:.2f}") else: print("You are not eligible for a bonus.")

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}")

ShakeSphereStuff commented 1 year ago
        # Silly thing I made that made me Mad!
        print("Welcome to MegaCorp, please state your details")
        userFirstName = input("First Name: ")
        print("Input 'Null' if you don't have a prefered Name ")
        userPreferedName = input("Prefered Name: ")
        userLastName = input("Last Name: ")
        userAge = input("Age: ")

        # What I used to bypass login, comment everything above and uncomment the comments below except for this line
        # userAge = 20
        # userFirstName = "Fred"
        # userPreferedName = "Freddy"
        # userLastName = "Kilm"
        # userPay = 0

        def findPercent(userInput):
            currentUserGrade = ""
            currentUserClass = ""
            classes = ["A", "B", "C", "D", "E", "F", "G"]
            for x in userInput:
                print(x)
                if(x.isdigit()):
                    currentUserGrade += x
                    continue
                for y in classes:
                    if x.upper() == y:
                        currentUserClass = y
                        continue
            currentUserGrade = int(currentUserGrade)
            return currentUserClass, currentUserGrade

        def MegaCorpFinance():
            global userPreferedName, userPay
            yearsOfEmployee = input(f"How many years have you served at the company {userPreferedName}? ")
            jobPay = { # Per year
                "Coder": 150000,
                "Janitor": 30000
            }
            for jobTitle in jobPay:
                print("\t*" + str(jobTitle))

            employeeTitle = input("Out of these, which is your job? ")

            for jobTitle in jobPay:
                if(employeeTitle.upper() == jobTitle.upper()):
                    print("Valid Title")
                    employeeTitle = jobTitle

            if(userPay == 0):
                userPay = jobPay[str(employeeTitle)]

            if(int(yearsOfEmployee) > 5):
                userPay *= 1.05 
            print(userPay)

        if(userPreferedName.upper() == "NULL"):
            userPreferedName = userFirstName
        else: 
            userPreferedName = userPreferedName

        if(int(userAge) > 18):
            print("Redirecting you to MegaCorpMain")
            MegaCorpFinance()
        elif(int(userAge) < 18):
            print(f"{userPreferedName}, we are redirecting you to MegaCollegeCorp")
            print("\tType: A + grade for your last History")
            print("\tType: B + grade for your last English")
            print("\tType: C + grade for your last Math")
            print("\tType: D + grade for your last Science")
            print("\tType: E + grade for your last Forign Language")
            print("\tType: F + grade for your last Fine Arts")
            print("\tType: G + grade for your last Electives")
            print("\tType Submit to submit your grades to us")
            userGrade = {
                    "A": "A", # History
                    "B": "A", # English
                    "C": "A", # Math
                    "D": "A", # Science
                    "E": "A", # Forign Language
                    "F": "A", # Fine Arts
                    "G": "A" # Electives
            }
            while 7 == 7:
                userInput = input("Input percents from your classes in base 10: ")
                userInput = userInput.replace(" ", "")
                print("User input is: " + str(userInput))
                classes = ["A", "B", "C", "D", "E", "F", "G"]
                grades = ["A", "B", "C", "D", "E", "F"]
                if(userInput.upper() == "SUBMIT"):
                    jobRequirements = {
                        "Coder": {
                            "A": "C",
                            "B": "B",
                            "C": "A",
                            "D": "A",
                            "E": "C",
                            "F": "C",
                            "G": "C"
                        },
                        "Jainitor": {
                            "A": "D",
                            "B": "D",
                            "C": "D",
                            "D": "D",
                            "E": "D",
                            "F": "D",
                            "G": "D"
                        }
                    }
                    for currentJob in jobRequirements:
                        amountOfRequirements = 0 
                        print(f"Scanning Requirement for {currentJob}")
                        for currentClassCheck in classes:
                            if(grades.index(jobRequiremets[currentJob][currentClassCheck]) >= grades.index(userGrade[currentClassCheck])):
                                amountOfRequirements += 1
                        if(amountOfRequirements > 4):
                            print(f"You got the application for {currentJob}!")
                            break

                    break
                percent = findPercent(userInput)
                currentUserGrade = int(percent[1])
                currentUserClass = percent[0]
                if(currentUserGrade > 80):
                    currentUserGrade = "A"
                elif(currentUserGrade >= 60):
                    currentUserGrade = "B"
                elif(currentUserGrade >= 50):
                    currentUserGrade = "C"
                elif(currentUserGrade >= 45):
                    currentUserGrade = "D"
                elif(currentUserGrade >= 25):
                    currentUserGrade = "E"
                else:
                    currentUserGrade = "F"
                userGrade[str(currentUserClass)] = currentUserGrade
                print(f"Class type {currentUserClass} is now set to grade {currentUserGrade}")
tanvim-18 commented 1 year ago

Get user input for citizenship status and age citizen_status = input("Are you a citizen? (yes/no): ").lower() age = int(input("Enter your age: "))

Check if the user is a citizen and 18 or older is_citizen = citizen_status == "yes" is_18_or_older = age >= 18

Use boolean logic to determine eligibility is_eligible_to_vote = is_citizen and is_18_or_older

Display the result if is_eligible_to_vote: print("You are eligible to vote. Go ahead and cast your vote!") else: print("Sorry, you are not eligible to vote. Please wait until you meet the criteria.")

2:

Get user input for salary and years of service salary = float(input("Enter your salary: ")) years_of_service = int(input("Enter your years of service: "))

Check if the employee is eligible for a bonus (more than 5 years of service) is_eligible_for_bonus = years_of_service > 5

Calculate the bonus amount (5% of salary) if eligible if is_eligible_for_bonus: bonus_percentage = 5 bonus_amount = (bonus_percentage / 100) * salary print(f"Congratulations! You are eligible for a {bonus_percentage}% bonus.") print(f"Net bonus amount: ${bonus_amount:.2f}") else: print("Sorry, you are not eligible for a bonus at this time.")

3:

Get user input for marks marks = float(input("Enter your marks: "))

Determine the grade based on the given rules 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"

Display the corresponding grade print(f"Your grade is: {grade}")

ShakeSphereStuff commented 1 year ago

Mistake with my code, the default for the ‘userGrade‘ should be “F” for all of them not “A”, this came about because it was easier to test than manually editing all of them every time I changed something. Please when executing change this mistake to: userGrade = { “A” : “F”, “B” : “F”, “C” : “F”, “D” : “F”, “E” : “F”, “F” : “F”, “G” : “F” }

Flying-Book commented 1 year ago
# Assume the voter's age and citizenship status
age = 18  # Adjust this value to the voter's age
is_citizen = True  # Set to True if the voter is a citizen, or False if not

# Determine voter eligibility
eligible_to_vote = age >= 18 and is_citizen

# Check if the voter is eligible and provide feedback
if eligible_to_vote:
    print("You are eligible to vote in the election.")
else:
    print("You are not eligible to vote in the election.")
# Get user input for salary and years of service
salary = float(input("Enter your salary: $"))
years_of_service = int(input("Enter your years of service: "))

# Check if the employee is eligible for a bonus
if years_of_service > 5:
    bonus_percentage = 5  # 5% bonus for more than 5 years of service
    bonus_amount = (bonus_percentage / 100) * salary
    print(f"You are eligible for a {bonus_percentage}% bonus.")
    print(f"Net bonus amount: ${bonus_amount:.2f}")
else:
    print("You are not eligible for a bonus.")
student_score = 0 

if student_score < 25:
    student_grade = "F"
elif 25 <= student_score <= 45:
    student_grade = "E"
elif 45 < student_score <= 50:
    student_grade = "D"
elif 50 < student_score <= 60:
    student_grade = "C"
elif 60 < student_score <= 80:
    student_grade = "B"
else:
    student_grade = "A"

print(student_grade)
parkib commented 1 year ago

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

Q2: salary = float(input("Enter your salary: $")) years_of_service = int(input("Enter your years of service: ")) bonus = 0.05 * salary if years_of_service > 5 else 0 print(f"Your net bonus amount is: ${bonus:.2f}")

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

SOoctosnake commented 1 year ago

https://sooctosnake.github.io/student_october//2023/10/10/boolean_condition.html

vibha-yganji commented 1 year ago

Problem 1: Voting Eligibility Check

Get user's citizenship status and age

is_citizen = input("Are you a citizen (yes/no)? ").lower() # Convert the input to lowercase for case-insensitivity age = int(input("Enter your age: "))

Check if the user is eligible to vote

if is_citizen == "yes" and age >= 18: print("You are eligible to vote.") else: print("You are not eligible to vote.")

Problem 2: Employee Bonus Calculation

Get employee's salary and years of service

salary = float(input("Enter your salary: ")) years_of_service = int(input("Enter the number of years of service: "))

Calculate the bonus amount

if years_of_service > 5: bonus = 0.05 * salary print(f"Your bonus amount is ${bonus:.2f}") else: print("You are not eligible for a bonus.")

Problem 3: Grading System

Get the user's marks

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

Determine the grade based on the given rules

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

Print the corresponding grade

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

vidhaganji commented 1 year ago

Problem 1: Voting Eligibility Check

Get user's citizenship status and age

is_citizen = input("Are you a citizen (yes/no)? ").lower() # Convert the input to lowercase for case-insensitivity age = int(input("Enter your age: "))

Check if the user is eligible to vote

if is_citizen == "yes" and age >= 18: print("You are eligible to vote.") else: print("You are not eligible to vote.")

Problem 2: Employee Bonus Calculation

Get employee's salary and years of service

salary = float(input("Enter your salary: ")) years_of_service = int(input("Enter the number of years of service: "))

Calculate the bonus amount

if years_of_service > 5: bonus = 0.05 * salary print(f"Your bonus amount is ${bonus:.2f}") else: print("You are not eligible for a bonus.")

Problem 3: Grading System

Get the user's marks

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

Determine the grade based on the given rules

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

Print the corresponding grade

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