errors and problems
- Make function is showing error, local host is not running (commit and push every time)
- I keep seeing an error every time I commit.
- it says “This workflow is waiting for Deploy Jekyll with GitHub Pages dependencies preinstalled to complete before running.”
- so I have
question I have
What is the difference between a notebook and post, they are showing up in same place
Calculator
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
return "Cannot divide by zero"
return x / y
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Enter choice (1/2/3/4): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
else:
print("Invalid input")
Select operation:
1. Add
2. Subtract
3. Multiply
4. Divide
4.0 + 3.0 = 7.0
Intro to python activity
print('Hello World!')
Hello World!
msg = input("Enter a greeting: ")
print(msg)
hello
Python Notes
procedural abstraction: grouping sequence of commands
procedure, function, def are all synonyms
“def” is a key word that defined a function
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
question_and_answer("Name the Python output command mentioned in this lesson?")
question_and_answer("If you see many lines of code in order, what would College Board call it?")
question_and_answer("Describe a keyword used in Python to define a function?")
Question: Name the Python output command mentioned in this lesson?
Answer: prompt
Question: If you see many lines of code in order, what would College Board call it?
Answer: procedural abstraction
Question: Describe a keyword used in Python to define a function?
Answer: "def"
response to “question_with_response”is captured in a variable called “rsp”.
if command is next command inn sequence after “rsp” assignment
the if command is only evaluated if true or false–true takes command under if and false taked branch of code directly under the else command
Build my own quiz
import getpass, sys
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
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_and_answer("Are you ready to take a test?")
rsp = question_with_response("What command is used to include other functions that were previously developed?")
if rsp == "import":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What command is used to evaluate correct or incorrect response in this example?")
if rsp == "if":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Each 'if' command contains an '_________' to determine a true or false condition?")
if rsp == "expression":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
Hello, sharonkodali running /Library/Developer/CommandLineTools/usr/bin/python3
You will be asked 3 questions.
Question: Are you ready to take a test?
Answer: yes
Question: What command is used to include other functions that were previously developed?
import is correct!
Question: What command is used to evaluate correct or incorrect response in this example?
if is correct!
Question: Each 'if' command contains an '_________' to determine a true or false condition?
expression is correct!
sharonkodali you scored 3/3