Showing posts with label October 14 2016. Show all posts
Showing posts with label October 14 2016. Show all posts

Monday, October 17, 2016

Random Python Programs: 1

Program Counts to 500
def counter(number):
    if number==1:
        print(number)
    if number<500:
        number+=1        print (number)
        counter(number)
counter(1)

Program Counts to 500
for counter in range(1,501):
    print(counter)

Program Counts Down from 500
counter=500while counter > 0:
    print(counter)
    counter-=1

Program Counts Odd Numbers Up to 19
counter = 1while counter <20:
    print(counter)
    counter +=2

Program Counts Odd Numbers Up to 19
for oddcounter in range(1,20,2):
    print(oddcounter)

Program Let's You See if a Number is Prime or Not
def prime_number(number):
    isprime = True    counter = 2    while counter <= number-1:
        if number%counter==0:
            isprime = False            counter+=1        return print(isprime)
number=int(input("Type in a Number to see if it is a Prime Number: "))
prime_number(number)

Friday, October 14, 2016

Programming In Class Notes October 14 2016


  • What are the Steps to Writing a Loop
    • Initialization
    • Check the Continuation condition, if yes keep going, if not, stop
    • Modification
  • How do you use the Range Function?
    • for variablename in range (start condition, end condition, Increment)
  • Why would you ever use while, instead of if?
    • While will continue to perform as long as its condition is met
  • How do you use a while function?
    • while variable_name condition number_or_variable:
  • What is the the symbol for modulo that allows you to find the remainder of two numbers divided by each other?
    • %
  • What is the purpose of break?
    • Break exists in order to stop a loop once a condition is met
    • Place break under a loop condition, in order to end the loop once that condition is met