comments: true layout: post title: Team Test IPYNB description: team test type: tangibles courses: { compsci: {week: 5} } —

Program Function and Purpose

Program with Output: Print Function Program with Input and Output: Python Quiz Program with a List: Cool kid list] Program with a Dictionary: word search Program with Iteration: sort through list Program with a Function to perform mathematical and/or a statistical calculations: Average Calculator Program with a Selection/Condition: Finish with a Program with Purpose: Pacman

print("hello")
hello
import getpass, sys
def question_with_response(prompt):
    print("Question: " + prompt)
    msg = input()
    return msg
questions = 3
correct = 0
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_with_response("Are you ready to take a test?")
rsp = question_with_response("What is the largest state in The United States?")
if rsp == "alaska":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")
rsp = question_with_response("What is the longest river in The United States?")
if rsp == "missouri river":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")
rsp = question_with_response("What was the first state created in The United States")
if rsp == "delaware":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
Hello, kasm-user running /bin/python
You will be asked 3 questions.
Question: Are you ready to take a test?
Question: What is the largest state in The United States?
alaska is correct!
Question: What is the longest river in The United States?
missouri river is correct!
Question: What was the first state created in The United States
delaware is correct!
kasm-user you scored 3/3
# Define an empty List called InfoDb
InfoDb = []


# InfoDB is a data structure with expected Keys and Values


# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({
"FirstName": "Jayden",
"LastName": "Chen",
"DOB": "May 31, 2007",
"Residence": "San Diego",
"Email": "jaydenchen16@gmail.com",
"Cool?": ["Yes"]
})


# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "Will",
"LastName": "Bartelt",
"DOB": "September 25, 2006",
"Residence": "San Diego",
"Email": "willbartelt@gmail.com",
"Cool": ["Yes"]
})


# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "Howie",
"LastName": "Nguyen",
"DOB": "January 21, 2007",
"Residence": "San Diego",
"Email": "howien07@gmail.com",
"Cool?": ["Yes"]
})


# Append to List a 3rd Dictionary of key/values
InfoDb.append({
"FirstName": "Nihar",
"LastName": "Gupta",
"DOB": "September 10, 2008",
"Residence": "San Diego",
"Email": "niharg@gmail.com",
"Cool?": ["NOPE"]
})


# Print the data structure
print(InfoDb)
[{'FirstName': 'Jayden', 'LastName': 'Chen', 'DOB': 'May 31, 2007', 'Residence': 'San Diego', 'Email': 'jaydenchen16@gmail.com', 'Cool?': ['Yes']}, {'FirstName': 'Will', 'LastName': 'Bartelt', 'DOB': 'September 25, 2006', 'Residence': 'San Diego', 'Email': 'willbartelt@gmail.com', 'Cool': ['Yes']}, {'FirstName': 'Howie', 'LastName': 'Nguyen', 'DOB': 'January 21, 2007', 'Residence': 'San Diego', 'Email': 'howien07@gmail.com', 'Cool?': ['Yes']}, {'FirstName': 'Nihar', 'LastName': 'Gupta', 'DOB': 'September 10, 2008', 'Residence': 'San Diego', 'Email': 'niharg@gmail.com', 'Cool?': ['NOPE']}]
from PyDictionary import PyDictionary


#Initialize the PyDictionary
dictionary = PyDictionary()


#Function to fetch the meaning of a word
def fetch_meaning(word):
try:
meanings = dictionary.meaning(word)
if meanings:
for part_of_speech, definition_list in meanings.items():
print(f"{part_of_speech}:")
for definition in definition_list:
print(f" - {definition}")
else:
print(f"Meaning not found for '{word}'")
except Exception as e:
print(f"An error occurred: {e}")


#Simple CLI interface for word lookup
while True:
user_input = input("Enter a word to lookup (or 'exit' to quit): ").strip()


if user_input.lower() == 'exit':
break


fetch_meaning(user_input)
# Define an empty List called InfoDb
InfoDb = []


# InfoDB is a data structure with expected Keys and Values


# Append to List a Dictionary of key/values related to a person and coolness
InfoDb.append({
"FirstName": "Jayden",
"LastName": "Chen",
"DOB": "May 31, 2007",
"Residence": "San Diego",
"Email": "jaydenchen16@gmail.com",
"Cool?": ["Yes"]
})


# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "Will",
"LastName": "Bartelt",
"DOB": "September 25, 2006",
"Residence": "San Diego",
"Email": "willbartelt@gmail.com",
"Cool?": ["Yes"]
})


# Append to List a 2nd Dictionary of key/values
InfoDb.append({
"FirstName": "Howie",
"LastName": "Nguyen",
"DOB": "January 21, 2007",
"Residence": "San Diego",
"Email": "howien07@gmail.com",
"Cool?": ["Yes"]
})


# Append to List a 3rd Dictionary of key/values
InfoDb.append({
"FirstName": "Nihar",
"LastName": "Gupta",
"DOB": "September 10, 2008",
"Residence": "San Diego",
"Email": "niharg@gmail.com",
"Cool?": ["Yes"]
})


# Print the data structure
print(InfoDb)


# This jupyter cell has dependencies on one or more cells above


# print function: given a dictionary of InfoDb content
def print_data(d_rec):
    print(d_rec["FirstName"], d_rec["LastName"]) # using comma puts space between values
    print("\t", "Residence:", d_rec["Residence"]) # \t is a tab indent
    print("\t", "Birth Day:", d_rec["DOB"])
    print("\t", "Coolness: ", end="") # end="" make sure no return occurs
    print(", ".join(d_rec["Cool?"])) # join allows printing a string list with separator
    print()




# for loop algorithm iterates on length of InfoDb
def for_loop():
    print("For loop output\n")
    for record in InfoDb:
        print_data(record) # call to function


for_loop() # call to function
[{'FirstName': 'Jayden', 'LastName': 'Chen', 'DOB': 'May 31, 2007', 'Residence': 'San Diego', 'Email': 'jaydenchen16@gmail.com', 'Cool?': ['Yes']}, {'FirstName': 'Will', 'LastName': 'Bartelt', 'DOB': 'September 25, 2006', 'Residence': 'San Diego', 'Email': 'willbartelt@gmail.com', 'Cool?': ['Yes']}, {'FirstName': 'Howie', 'LastName': 'Nguyen', 'DOB': 'January 21, 2007', 'Residence': 'San Diego', 'Email': 'howien07@gmail.com', 'Cool?': ['Yes']}, {'FirstName': 'Nihar', 'LastName': 'Gupta', 'DOB': 'September 10, 2008', 'Residence': 'San Diego', 'Email': 'niharg@gmail.com', 'Cool?': ['Yes']}]
For loop output

Jayden Chen
	 Residence: San Diego
	 Birth Day: May 31, 2007
	 Coolness: Yes

Will Bartelt
	 Residence: San Diego
	 Birth Day: September 25, 2006
	 Coolness: Yes

Howie Nguyen
	 Residence: San Diego
	 Birth Day: January 21, 2007
	 Coolness: Yes

Nihar Gupta
	 Residence: San Diego
	 Birth Day: September 10, 2008
	 Coolness: Yes
%%html
<style>
  .calculator-output {
    /* calulator output 
      top bar shows the results of the calculator;
      result to take up the entirety of the first row;
      span defines 4 columns and 1 row
    */
    grid-column: span 4;
    grid-row: span 1;
  
    padding: 0.25em;
    font-size: 20px;
    border: 5px solid black;
  
    display: flex;
    align-items: center;
  }
</style>

<!-- Add a container for the animation -->
<div id="animation">
  <div class="calculator-container">
      <!--result-->
      <div class="calculator-output" id="output">0</div>
      <!--row 1-->
      <div class="calculator-number">1</div>
      <div class="calculator-number">2</div>
      <div class="calculator-number">3</div>
      <div class="calculator-operation">+</div>
      <!--row 2-->
      <div class="calculator-number">4</div>
      <div class="calculator-number">5</div>
      <div class="calculator-number">6</div>
      <div class="calculator-operation">-</div>
      <!--row 3-->
      <div class="calculator-number">7</div>
      <div class="calculator-number">8</div>
      <div class="calculator-number">9</div>
      <div class="calculator-operation">*</div>
      <!--row 4-->
      <div class="calculator-clear">A/C</div>
      <div class="calculator-number">0</div>
      <div class="calculator-number">.</div>
      <div class="calculator-equals">=</div>
  </div>
</div>

<!-- JavaScript (JS) implementation of the calculator. -->
<script>
  // initialize important variables to manage calculations
  var firstNumber = null;
  var operator = null;
  var nextReady = true;
  // build objects containing key elements
  const output = document.getElementById("output");
  const numbers = document.querySelectorAll(".calculator-number");
  const operations = document.querySelectorAll(".calculator-operation");
  const clear = document.querySelectorAll(".calculator-clear");
  const equals = document.querySelectorAll(".calculator-equals");

  // Number buttons listener
  numbers.forEach(button => {
    button.addEventListener("click", function() {
      number(button.textContent);
    });
  });

  // Number action
  function number (value) { // function to input numbers into the calculator
      if (value != ".") {
          if (nextReady == true) { // nextReady is used to tell the computer when the user is going to input a completely new number
              output.innerHTML = value;
              if (value != "0") { // if statement to ensure that there are no multiple leading zeroes
                  nextReady = false;
              }
          } else {
              output.innerHTML = output.innerHTML + value; // concatenation is used to add the numbers to the end of the input
          }
      } else { // special case for adding a decimal; can not have two decimals
          if (output.innerHTML.indexOf(".") == -1) {
              output.innerHTML = output.innerHTML + value;
              nextReady = false;
          }
      }
  }

  // Operation buttons listener
  operations.forEach(button => {
    button.addEventListener("click", function() {
      operation(button.textContent);
    });
  });

  // Operator action
  function operation (choice) { // function to input operations into the calculator
      if (firstNumber == null) { // once the operation is chosen, the displayed number is stored into the variable firstNumber
          firstNumber = parseInt(output.innerHTML);
          nextReady = true;
          operator = choice;
          return; // exits function
      }
      // occurs if there is already a number stored in the calculator
      firstNumber = calculate(firstNumber, parseFloat(output.innerHTML)); 
      operator = choice;
      output.innerHTML = firstNumber.toString();
      nextReady = true;
  }

  // Calculator
  function calculate (first, second) { // function to calculate the result of the equation
      let result = 0;
      switch (operator) {
          case "+":
              result = first + second;
              break;
          case "-":
              result = first - second;
              break;
          case "*":
              result = first * second;
              break;
          case "/":
              result = first / second;
              break;
          default: 
              break;
      }
      return result;
  }

  // Equals button listener
  equals.forEach(button => {
    button.addEventListener("click", function() {
      equal();
    });
  });

  // Equal action
  function equal () { // function used when the equals button is clicked; calculates equation and displays it
      firstNumber = calculate(firstNumber, parseFloat(output.innerHTML));
      output.innerHTML = firstNumber.toString();
      nextReady = true;
  }

  // Clear button listener
  clear.forEach(button => {
    button.addEventListener("click", function() {
      clearCalc();
    });
  });

  // A/C action
  function clearCalc () { // clears calculator
      firstNumber = null;
      output.innerHTML = "0";
      nextReady = true;
  }
</script>

<!-- 
Vanta animations just for fun, load JS onto the page
-->
<script src="/student/assets/js/three.r119.min.js"></script>
<script src="/student/assets/js/vanta.halo.min.js"></script>
<script src="/student/assets/js/vanta.birds.min.js"></script>
<script src="/student/assets/js/vanta.net.min.js"></script>
<script src="/student/assets/js/vanta.rings.min.js"></script>

<script>
// setup vanta scripts as functions
var vantaInstances = {
  halo: VANTA.HALO,
  birds: VANTA.BIRDS,
  net: VANTA.NET,
  rings: VANTA.RINGS
};

// obtain a random vanta function
var vantaInstance = vantaInstances[Object.keys(vantaInstances)[Math.floor(Math.random() * Object.keys(vantaInstances).length)]];

// run the animation
vantaInstance({
  el: "#animation",
  mouseControls: true,
  touchControls: true,
  gyroControls: false
});
</script>
0
1
2
3
+
4
5
6
-
7
8
9
*
A/C
0
.
=
x = 100


if x > 5:
    print("x is greater than 5")
else:
    print("x is not greater than 5")
x is greater than 5
menu = {"burger": 3.99,
"fries": 1.99,
"drink": 0.99}
total = 0


#shows the user the menu and prompts them to select an item
print("Menu")
for k,v in menu.items():
    print(k + " $" + str(v)) #why does v have "str" in front of it?


#ideally the code should prompt the user multiple times
item = input("Please select an item from the menu")


#code should add the price of the menu items selected by the user
print(total)

Menu
burger $3.99
fries $1.99
drink $0.99
0
menu = {
"burger": 3.99,
"fries": 1.99,
"drink": 0.99
}


bill = []


# Display the menu
print("Menu")
for item, price in menu.items():
    print(f"{item}: ${price:.2f}")


while True:
    item = input("Please select an item from the menu (or enter 'done' to finish): ").lower()


    if item == 'done':
        break


    if item in menu:
        bill.append(menu[item])
        print(f"{item.capitalize()} added to the bill.")
    else:
        print("Invalid item. Please select an item from the menu or enter 'done' to finish.")


if bill:
    total_cost = sum(bill)
    print(f"Your total bill amount is: ${total_cost:.2f}")
else:
    print("No items selected. Have a nice day!")
Menu
burger: $3.99
fries: $1.99
drink: $0.99
Invalid item. Please select an item from the menu or enter 'done' to finish.
Burger added to the bill.
Fries added to the bill.
Drink added to the bill.
Burger added to the bill.
Your total bill amount is: $10.96