Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Programming

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Introduction to Programming

These are the slides from my Introduction to Programming course taught as part of Delta Sigma Pi's professional development program.

Avatar for Dylan Staley

Dylan Staley

March 11, 2014

Other Decks in Education

Transcript

  1. 'H'

  2. 1

  3. 2.5

  4. b = 10 if b > 5: # do that

    else: # do this
  5. b = 4 if b > 5: # do that

    else: # do this
  6. b = 5 if b > 5: # do that

    else: # do this
  7. if num % 5 == 0 and num % 3

    == 0: # number is divisible by 3 and 5
  8. if num % 5 == 0 and num % 3

    == 0: # number is divisible by 3 and 5 elif num % 5 == 0: # number is divisible by 5 elif num % 3 == 0: # number is divisible by 3 else: # number is not divisible by 3 or 5
  9. "Write a program that prints the numbers from 1 to

    100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”."
  10. "Most good programmers should be able to write out on

    paper a program which does this in a under a couple of minutes. ! Want to know something scary ? – the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution."
  11. def fizzbuzz(num): if num % 5 == 0 and num

    % 3 == 0: return "FizzBuzz" elif num % 5 == 0: return "Buzz" elif num % 3 == 0: return "Fizz" else: return num
  12. def sum(start, stop): result = 0 for num in range(start,

    stop + 1): result = result + num return result ! print(sum(1,5))
  13. def fizzbuzz(number): if num % 5 == 0 and num

    % 3 == 0: return "FizzBuzz" elif num % 5 == 0: return "Buzz" elif num % 3 == 0: return "Fizz" else: return num
  14. def digit_sum(number): sum = 0 for digit in str(number): sum

    = sum + int(digit) return sum ! print(digit_sum(1234))
  15. def anti_vowel(s): result = "" for letter in s: if

    ( letter.lower() != 'a' and letter.lower() != 'e' and letter.lower() != 'i' and letter.lower() != 'o' and letter.lower() != 'u'): result = result + letter return result ! print(anti_vowel("Hey look it works!"))
  16. def reverse(string): result = "" for char in string: result

    = char + result return result ! print(reverse("Hello"))
  17. def factorial(number): result = 1 for num in range(2, number

    + 1): result = result * num return result ! print(factorial(5))