3.5-3.7 Student Lesson (group 3)
My homework for the 3.5-3.7 lesson
ispassing = False
isstudentpassing = not(ispassing)
print(isstudentpassing)
temp = input("what is the temperature today?")
if int(temp) >= 40 and int(temp) <= 70:
print("Bring a hoodie!")
if int(temp) < 40:
print("bring snow gear!")
if int(temp) > 70:
print("No jacket today!")
APscore = 4
Finalscore = 68
if APscore >= 3 or Finalscore >= 75:
print("student passed this class")
else:
print("student did not pass this class")
Hack 2: 3.6
[x] Level I: Vowel Count Return the number (count) of vowels in the given string. We will consider a, e, i, o, u as vowels for this challenge (but not y). The input string will only consist of lower case letters and/or spaces.
Hint: If you use a lot of if-statements and there are more than one outcome, that is to be expected. If not, don't panic, just keep trying.
[x] Level III: Mutliples of 3 or 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. Additionally, if the number is negative, return 0 (for languages that do have them).
Note: If the number is a multiple of both 3 and 5, only count it once.
Hint: What do you know about for loops? Since your code incorporates a list of numbers from 1 to the max number, can you use for loops along with conditionals?
[x] binary conditional logic [x] define key terms
Defining Key Terms:
- Boolean: a boolean is an operator that determines if a condition is true or false
- Selection: When an algorithm must make a decision (if a condition is met)
- AND: AND is a logical operator that determines of 2 conditions are both met
- OR: OR is a logical operator that determines if 1 of 2 conditions is met
- NOT: NOT is a logical operator that displays the oposition condition of the data
gpa = 4.0
extracirriculars = "present"
if gpa >= 4.0 and extracirriculars == "present":
major = input("What is your major")
if major == "math" or major == "science":
print("You have been accepted into our STEM program!")
elif major == "english" or major == "history":
print("You have been accepted into our arts program!")
else:
print("You have been accepted into our " + major + " program!")
else:
print("I'm sorry, you are not accepted to this program")
input_string = input("Input a string to check how many vowels it has. ")
vowelcount = 0
for character in input_string: #iterates through the string character by character
if character == "a":
vowelcount += 1
elif character == "e":
vowelcount += 1
elif character == "i":
vowelcount += 1
elif character == "o":
vowelcount += 1
elif character == "u":
vowelcount += 1
print(vowelcount)
numberstring = input("Input a number to find the sum of all the multiples of 3 or 5 below it. ")
numbertocheck = int(numberstring)
totalmultiples = 0
if numbertocheck >= 0: # if the number is negative it will display the sum as 0
for n in range(numbertocheck+1):
if n/3 == int(n/3): #checks for multiples of 3
print(str(n) + " is a multiple of 3")
totalmultiples += n #elif prevents duplicates of numbers with both multiples of 3 and 5
elif n/5 == int(n/5): # checks for multiples of 5
print(str(n) + " is a multiple of 5")
totalmultiples += n
print(totalmultiples)
Hack 3
[x] For the first hack, pretend you are a school's test grader. Create an array with integers, each integer representing one score from a student's taken tests. If the average of the student's test scores are at least 75 percent, then display that the student is elligible for credit, and if not, display that the student must retake the tests over break. [x] The second hack is more number-oriented. Create an algorithm that calculates the sum of two numbers, then determines whether the sum is greater than or less than 100. [x] The hacks above was heavily derived from CollegeBoard. As a computer science student, you should be able to create an algorithm utilizing conditionals. Try something number-oriented if you get stuck. Creativity gets points.
def average(lst):
return sum(lst)/len(lst)
gradelist = [92, 83, 90, 74, 86, 97]
averagegrade = average(gradelist)
print(str(averagegrade) + " is the student's grade average")
if averagegrade >= 75:
print("student is eligible for credit")
else:
print("student needs to retake tests during break")
num1 = input("What is your first number?")
num2 = input("What is your second number?")
sumofnumbers = int(num1) + int(num2)
if sumofnumbers >= 100:
print(str(sumofnumbers) + " is greater than or equal to 100")
else:
print(str(sumofnumbers) + " is less than than 100")
# to test if a show is included in Netflix, and if it is recommended
showdictionary = {
'Wednesday':5, # key=title name and value=rating out of 5 stars
'You':3,
'Knight Before Christmas':4,
'Red Notice':5,
'Truth or Dare':1
}
show = input("What show are you looking for?")
if show in showdictionary.keys():
print(show + " is available on Netflix")
if showdictionary[show] >= 3:
print("show/movie is recommended")
else:
print("show is not recommended")
else:
print(show + " is not available on Netflix")
Hack 4
[x] Create 3 differnt flow charts representing nested statements and transfer them into code. [] Create a piece of code that displays four statements instead of three. Try to do more if you can. [x] Make piece of code that gives three different recommandations for possible classes to take at a school based on two different condtions. These conditions could be if the student likes STEM or not.
STEM = input("Are you intrested in STEM? Y or N")
if STEM == "Y":
subject = input("Do you like math or science better?")
if subject == "math":
print("Class recommendations: Advanced Function Analysis, AP Calculus AB, AP Calculus BC, AP Statistics")
if subject == "science":
print("Class recommendations: Chemistry, Physics, AP Enviornmental Science, AP Physics, AP Chemistry")
else:
language = input("Are you intrested in language? Y or N")
if language == "Y":
lansubject = input("Do you prefer a foreign language or English?")
if lansubject == "foreign language":
print("Class recommendations: Spanish, Mandarin, AP Spanish, AP Mandarin")
if lansubject == "English":
print("Class recommendations: American Literature, AP English Literature")
if language == "N":
print("See class list for more options!")
<!-- <img src="_images/ColdFlowChart.png" alt="flowchart1">
temp = input("what is the temperature today?")
if int(temp) <= 73:
print("It is cold!")
if int(temp) <= 40:
print("Bring a snow jacket!")
else:
print("Bring a hoodie!")
else:
print("It's warm today! Don't bring a jacket :)")
<!-- <img src="_images/Istheclassdifficult.png" alt="flowchart2">
passingrate = 72
testaverage = 82
if passingrate > 70 and passingrate <= 100:
if testaverage >= 80:
print("This class is not difficult")
else:
print("this class is difficult")
else:
print("this class is difficult")
<!-- <img src="_images/Offrollflowchart.png" alt="flowchart3"> -->
feeling = input("Are you tired today?")
if feeling == "yes":
print("Stay home and sleep")
if feeling == "no":
homework = input("Do you have homework to do?")
if homework == "yes":
print("Go to school")
else:
print("Stay home and sleep")
drinkable = "potable"
temperature = "warm"
if drinkable == "potable":
print("water is potable")
if temperature == "cold":
print("water is " + str(temperature))
print("water is in ideal condition")
print("drink up!")
else:
print("water is " + str(temperature))
print("water is not in ideal condition")
print("chill with ice")
else:
print("do not drink, water is not potable")