#!/usr/bin/env python # coding: utf-8 # In[12]: # Section 3.6 -- Boolean variables # Recall x=0 y=1 print("type(x 102.5 degrees, then you are instructed to turn the # thermostat down & re-measure the temp 5 minutes later. If the temp is <= 102.5 # then you are told to run program again in 15 minutes. # magic number TEMP_CUTOFF=102.5 current_temp=float(input("What is the current temperature?")) while(current_temp>TEMP_CUTOFF): print("Turn thermostat down and report the temperature in 5 minutes.") current_temp=float(input("What is the current temperature reading?")) print("Run this program again in 15 minutes to retest the temperature.") # In[29]: # 4.3 for loop -- (count-controlled) # # for var in [value1, value2, value3, ..., value n]: # do stuff # do stuff # etc # # A new data type: a "list" is used here # lists are specified as [value1, value2, value3, ..., value n] mylist=['a','b',2.1,3.1234,True] print("type(mylist) is",type(mylist)) print(mylist) # we can extract the items in a list #first item print("type(mylist[0]) is",type(mylist[0])) print(mylist[0]) #second item print(mylist[1]) #third item print(mylist[2]) ###### ###### # In[42]: # Printing prime numbers in a list primes=[2,3,5,7,11,13,17,19,23,29] for num in primes: print(num) # Print people beatles=['Ringo','Paul','John','George'] for member in beatles: print(member) #range function print("type(range(5)) is",type(range(5))) print("list(range(5)) is",list(range(5))) print("list(range(10)) is",list(range(10))) print("list(range(5,20)) is",list(range(5,20))) # range(a,b) will give us a list of integers starting at a and ending at b-1 for value in range(5): print("Hello world!") # In[50]: # Make a table of perfect squares print("Number \t Square \t Cubes") print("------------------------------") for num in range(1,21): print(num,"\t",num**2,"\t\t",num**3) # In[59]: # User-defined list of squares firstnum=int(input("What is the starting number for the list of squares?")) lastnum=int(input("What is the last number for the list of squares?")) print("Number \t Square") print("----------------") for num in range(firstnum,lastnum+1): print(num,"\t",num**2)