### Computer 12 Quiz Thursday, March 8, 2018

For our quiz on Thursday, March 8, 2018, you will be given an example of code and expected to produce the output.  Tuesday you a chance to ask any questions.  Here is an example of what you might expect and how you would answer:

Sample Code:

```#include <stdio.h>
int main(int argc, char** argv){

int x=5;
printf ("the value of x=%d\n",x);

do{
printf("x is %d\n",x);
x--;
}while(x>0);

printf("DONE!!!\n");
return(0);
}
```

This code will produce the following output:

```the value of x=5
x is 5
x is 4
x is 3
x is 2
x is 1
DONE!!!
```

mrcampbell / March 2, 2018 / Computer 12

### Computer 12 Python Update

Today we finished our introduction to programming using Python.  Our main objective in this segment is to learn basic programming concepts, including output, input, looping, conditionals, variables, and functions.  The culmination of this segment of instruction was building a simple text-based calculator. Here is a sample of one of our calculators:

```#add function
result=a+b
return(result)
#subtract
def subtract(a,b):
result=a-b
return(result)
#multiply
def multiply(a,b):
result=a*b
return (result)
#divide
def divide(a,b):
result=a/b
return(result)
#Circumference
def Circumference(r):
circ=2*3.14159*r
return(circ)

#main function
def main():
#set selection = to 1 so the condition to start
#our while loop is true
selection=1
while selection>0:
print("2: Subtract")
print("3: Multiply")
print("4: Divide")
print("5: Circumference")
#get the user input
UserChoice=input("Please make a choice or 0 to exit: ")
#convert it to an integet
selection=int(UserChoice)
#if the choice is 0 we are finished!
if(selection==0):
print ("Goodbye")
elif selection>0 and selection<5: #an operation requiring 2 numbers
#Do Math!
#Get 2 Numbers and convert them to integers
num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))
#perform the desired operation
if selection==1:
if selection==2:
x=subtract(num1,num2)
if selection==3:
x=multiply(num1,num2)
if selection==4:
x=divide(num1,num2)
#display the result
print("The result of your operation is: ",x)
elif selection==5: # we only need the radius to calculate the Circumference