# Tutorial Problem 1
# Generate a requested number of terms in the Fibonacci Sequence.
def main() :
numTerms = int(input("Enter the number of terms desired: ")
while numTerms <= 0 :
numTerms = int(input("That value is not legal, please try again: ")
term1
# Using turtle graphics to draw a filled regular polygon
from turtle import *
def main() :
# Set appearance of turtle
shape("turtle")
# Set the line thickness and colour
pensize(5)
speed(2)
pencolor("blue")
fillcolor("yellow")
# Move turtle down a bit wit
# This program demonstrates the use of a pass statement
# You will need to type <Cntrl>c to terminate this program
def main() :
print("Type <Cntrl>c whenever you are ready!")
# A loop that waits for a keyboard interrupt.
while True :
pass
# An if statemen
# This program displays the numbers b/w 5 and 100 by jumps of 5
# One number per line.
print("A count from 5 to 100 in steps of 5")
for i in range(5,101,5) :
print(i),
#This program converts a distance in inches to cm
def main():
distanceInches=float(input("Please enter a distance in inches: ")
distanceCm= 2.54 * distanceInches
print("Distance is cfw_0:.1fcm." .format(distanceCm)
main()
#
#
#
#
The factorial demo for CISC101
This program calculates and displays all the factorials up to that
of a supplied number. It also demonstrates Python's capability of storing
*very* large integers!
def main() :
userNum = 0
while userNum <= 1 :
userNu
#This program takes a radius and outputs the circumference, area, volume
def main():
radius = float(input("Please entera radius: ")
circumference = 2*3.14*radius
area = 3.14*(radius*2)
volume = (4/3)*3.14*(radius*3)
print("The circumference of a circle is
# Using turtle graphics to draw a stop sign
from turtle import *
def main() :
# Set appearance of turtle
shape("turtle")
# Set the line thickness and colour
pensize(5)
speed(2)
pencolor("red")
fillcolor("red")
# Move turtle down a bit without drawing
penu
def main() :
integer = int(input("Please enter a integer.")
while integer <= 1:
int(input("Please eneter a integer.")
x = 1
aList =[]
while x<= integer :
if (integer % x) = 0:
x += 1
print(aList, sep = ",", end = ".")
main()
# Version 2
# This program tells a Queen's student what to wear.
# Another version just using a chained if structure.
def main() :
temp = int(input("Outdoor temperature: ")
time = int(input("How many minutes to get there: ")
if time < 5 :
clothes = "short
# The problem is to determine the charge for a $99 package, given a set of
quantity discounts:
# < 10
no discount
# between 10 and 19
20%
# between 20 and 49
30%
# between 50 and 99
40%
# >= 100
50%
def main():
costPerItem = 99.0
# dollars
quantity = int(
#
#
#
#
This code is an example of the use of an if-elif or "chained" if statement.
It accepts a numeric mark from the user and outputs the equivalent
letter grade using some bogus marking scheme. Note the use of the
return statement to end main() early i
# The second part of exercise 4.1
# (A silly program.)
def main ():
# We'll assume that the user enters an int, not a float
limit1 = int(input("Please enter the starting number: ")
limit2 = int(input("Please enter the finishing number: ")
if abs(limit1 -
# This program calculates a monthly mortgage payment and the total interest
# paid for user-supplied values of the interest rate, principal and term.
def main():
# Obtain input parameters from the user and check for legality of each:
# Payment Term in yea
# This is another lecture demo program that obtains numbers from the user, one
# at a time, adds them up and displays their average. It is another
illustration
# of a conditional inside a loop and how to use input to stop a loop.
def main():
print("Enter
#
#
#
#
An example program that demonstrates the use of global variables
used as constants. You can also see the use of a doc string.
The program is used to calculate the weight of sheets of window glass.
by Prof. McLeod for CISC101
# Global variables use
# A Demo of various list BIFs and how they are used with loops.
def main() :
# Create some fodder for the functions to play with!
names = ["Bev", "Alan", "Wags", "Geoff", "Graeme"]
ages = [18, 21, 7, 20, 14]
sexes = ["F", "M", "cat!", "M", "M"]
# We've se
#
#
#
#
This program calculates the area of a triangle given three
side lengths supplied by the user.
This second version checks the numeric input to make sure the
values are legal.
def main() :
# Obtain three side lengths from the user
side1 = float(inpu
#
#
#
#
A program that indicates the order of three numbers provided by the user
The program does not sort the numbers, it just uses a maximum of three
comparisons in a row to determine the order.
This is an illustration of the use of nested if statements
# This program tells a Queen's Student what to wear.
# Version 3 Modification.
# Asumption that destination = class yields a 'pants' result.
def main() :
temp
= int(input("Outdoor temperature: ")
time
= int(input("How many minutes to get there: ")
destina
# Version 0
# This program tells a Queen's student what to wear.
# No nesting is used, just a series of if statements.
def main() :
temp = int(input("Outdoor temperature: ")
time = int(input("How many minutes to get there: ")
if time < 5 :
clothes = "shor
# This program calculates a monthly mortgage payment and the total interest
# paid for user-supplied values of the interest rate, principal and term.
# Functional version.
def getNum(prompt, lowLimit, highLimit) :
inputOK = False
while not inputOK :
try :
# Version 3
# This program tells a Queen's student what to wear.
# A nested if structure with the time choice as the outer conditional.
def main() :
temp = int(input("Outdoor temperature: ")
time = int(input("How many minutes to get there: ")
if time < 5
#
#
#
#
#
This program is used with exercise 3.2 of lab 3
You are to figure out what the output is for the following
inputs: -10, 2000, 50, 61, 900, 850 by just examining the code.
Run the program after you have figured it out yourself to check your
answe
# Version 1
# This program tells a Queen's student what to wear.
# No nesting is used, just a chained if statement.
def main() :
temp = int(input("Outdoor temperature: ")
time = int(input("How many minutes to get there: ")
clothes = "pants and parka"
if t
Week 8
Page ! 1 of 31
!
CISC-102
Fall 2016
Week 8
The Pigeon Hole Principle
If there are n pigeons, that all must sleep in a pigeon hole,
and n-1 pigeon holes, then there is at least one pigeon
hole where (at least) 2 pigeons sleep.
This should be obvious
Week 7
page ! 1 of 34
!
CISC-102
Fall 2016
Week 7
Congruence Relations
Let a and b be integers. We say that a is congruent to b
modulo m written as:
a b (mod m)
and defined as follows:
a b (mod m) if m | (a-b).
An equivalent way of viewing congruence is:
Week 6
page 1! of 15
!
CISC-102
Fall 2016
Week 6
We will see two different, yet similar, proofs that there are infinitely many prime numbers. One
proof would surely suffice. However, seeing two different ways of proving the same result is
instructive, as
Week 4
Fall 2016
1 of 17
CISC-102
Fall 2016
Week 4
Functions
We have already seen functions in this course. For example:
x2 4x + 3
We could also write this function as an equation:
y = x2 4x + 3
In this example you can think of plugging in a (Real) value
At the end of the game, they count how much money they have. They do not
borrow from each other, so that each cannot loose more than his p pennies. How
Week 10 results are there?
many possible
page ! 1 of 27
!
3.5 Pascals
CISC-102
Fall 2016
Triangle Week