-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
P1 Developing Algorithms | Compci Blogs #36
Comments
All the homework is included in this one program. They are separated into respective functions. |
Hw 1: List of test gradestest_grades = [85, 92, 78, 90, 88, 76, 94, 89, 81, 87] Calculate the medianmedian_grade = statistics.median(test_grades) Print the median test gradeprint("The median test grade is: {median_grade}") (edited) https://github.com/devaSas1/student/blob/main/_notebooks/2023-10-17-DevelopingAlgorithms.ipynb |
median test gradetxt = str(input("enter grades with spaces between grades"))
x = txt.split()
for i in range(len(x)):
x[i] = int(x[i])
median = 0
if((len(x))%2==0):
median = (x[int(len(x)/2)]+x[int(len(x)/2)-1])/2
else:
median = x[int(len(x)/2)]
print(median) simple gameimport random
choice = random.randint(1,6)
answer = int(input("Rolling a 6 sided die, choose a side to bet on"))
if answer == choice:
print("you won")
else:
print("sucks to be you") jonathan liu |
#1: #2:
print("Game Over. Thanks for playing!") |
##Student Teaching, Algorithms ###Find the median test grade of a class testscores = [85, 92, 78, 90, 88, 76, 95, 89, 83, 91] testscores.sort() num_scores = len(testscores) if num_scores % 2 == 1: print(f"The median test score is: {median}") Create a simple game with numbersimport random secret_number = random.randint(1, 100) attempts = 0 while True:
|
1:scores = [78, 82, 68, 75,927, 89, 63, 72] 2:import random print("Game Over.") |
#1: #2:
except ValueError: |
1#
test_grades = [85, 92, 78, 90, 88, 95] 2# def roll_dice(): def play_game():
if name == "main": |
def find_median(grades):
test_grades = [74, 93, 36, 95, 87, 94, 92, 81]
import random def higher_or_lower_game():
print("Welcome to the higher or lower game!") |
Find the median test Scores:
Example usage:class_scores = [85, 90, 92, 78, 88, 95, 89] A number guessing game: def guess_the_number():
Run the gameguess_the_number() |
test_scores = [85, 92, 78, 90, 88, 76, 84, 89, 94, 87] |
function findMedian(data) {
} // Example #2 x = input("Do you want to flip a coin? (y/n)") if x == "y": If they don't want to flip a coinelif x == "n": |
First Assignmentstudents = []
def addStudent(name): def makeAssignments(assignmentName, assignmentTotal): def gradeAssignment(studentName, assignmentName, grade): def startUp():
startUp() Second Oneimport time currentMove = 0 toMove = [] def createAnimals(): def animalMoves():
def startUp(): def decompileVerts(): def screen(): def walk(moves, currentObj):
def movements():
startUp() |
Don’t know why there’s an indent for the last 5 lines, please reinsert the indents after, there’s a lot of them to account for |
Actually, here’s the proper ones Number 2
Number 1students = []
def addStudent(name): def makeAssignments(assignmentName, assignmentTotal): def gradeAssignment(studentName, assignmentName, grade): def startUp():
startUp() |
Sorry, proper number 1:
|
Best I could do ^ |
def find_median(test_grades):
List of test gradestest_grades = [85, 92, 78, 90, 88, 76, 84, 89, 95, 91] Calculate the medianmedian_grade = find_median(test_grades) print(f"The median test grade is: {median_grade}") number = random.randint(1,10) |
1. Write Python Code or Psuedo Code that is able to take a string as input and detect if its a palindromedef is_palindrome(input_string): input_string = input("Enter a string: ") if is_palindrome(input_string) == True: 2. Create a program that uses at least 1 of the algorithmic concepts covered in this notebook in a real-world applicationdef binary_search(arr, target): arr = [1, 3, 5, 7, 9, 11, 13] |
|
def find_median(grades):
List of test gradestest_grades = [85, 92, 78, 90, 88, 76, 94, 89, 87, 91] Calculate the median using the algorithmmedian_grade = find_median(test_grades) Print the median test gradeprint("Median test grade:", median_grade) import random Generate a random number between 1 and 100secret_number = random.randint(1, 100) attempts = 0 while True:
|
#1 Sort the grades in ascending ordersorted_grades = sorted(test_grades) n = len(sorted_grades) Check if the number of grades is odd or evenif n % 2 == 1: return median Calculate the median print(f"The median test grade is: {median_grade}") #2 Generate a random number between 1 and 100 attempts = 0 while True: Get the player's guessguess = int(input("Guess the secret number (between 1 and 100): ")) if guess < secret_number: |
Q1: grades = [] grades.sort() n = len(grades) print(f"The median test grade is: {median}") Q2: List of words for the gamewords = ["python", "banana", "tiger", "elephant", "computer", "guitar", "pizza"] Select a random word from the listword_to_guess = random.choice(words) Create a list to store guessed lettersguessed_letters = ["_"] * len(word_to_guess) print("Welcome to the Word Guessing Game!") while "_" in guessed_letters:
print(f"Congratulations! You guessed the word: {word_to_guess}") |
List of test gradestest_grades = [85, 92, 78, 90, 88, 76, 89, 94, 81, 87] Sort the list in ascending ordertest_grades.sort() Calculate the mediann = len(test_grades) print(f"The median test grade is: {median}") import random Generate a random number between 1 and 100secret_number = random.randint(1, 100) attempts = 0 while True:
|
1 similar comment
List of test gradestest_grades = [85, 92, 78, 90, 88, 76, 89, 94, 81, 87] Sort the list in ascending ordertest_grades.sort() Calculate the mediann = len(test_grades) print(f"The median test grade is: {median}") import random Generate a random number between 1 and 100secret_number = random.randint(1, 100) attempts = 0 while True:
|
Sample list of numbersnumbers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] Using list indexing and list procedures to calculate the sum of the first five elementssum_of_first_five = sum(numbers[:5]) Calculate the average of the first five elementsaverage_of_first_five = sum_of_first_five / len(numbers[:5]) print(f"Sum of the first five elements: {sum_of_first_five}") def worst_case_iterations(length): import math array_length = 20 print(f"Worst-case number of iterations for binary search on an array of length {array_length}: {worst_case}") |
P1 Developing Algorithms | Compci Blogs
Lesson for developing algorithms in Python
https://nighthawkcoders.github.io/teacher/2023/10/09/P1_developingalgorithms_IPYNB_2_.html
The text was updated successfully, but these errors were encountered: