# -*- coding: utf-8 -*- """ Created on Wed Sep 21 10:59:05 2022 @author: cpresser """ all_rolls = [0,0,0,0,0,0] print(all_rolls) all_rolls = [0]*6 print(all_rolls) #list compression #repeat a value all_rolls = [0 for i in range(6)] print(all_rolls) #calculate a value from a range list = [i for i in range(10)] print(list) #calculate a value from another list odds = [2*n+1 for n in list] print(odds) #same thing odds = [] for n in list: odds.append(2*n+1) print(odds) #nested loops (one loop inside another) for i in range(4): print(i) for i in range(4): #outer loop #repeat a loop for j in range(5): #inner loop print(f"{i},{j}", end="; ") print() # this repeats in outer loop for i in range(4): #repeat the loop, up to i #first i is 0 for j in range(i): #when i == 0, j is range(0) which is 0 to 0 w/o 0 #when i == 1, j is range(1) 0 to 1 w/o 1 # i == 2, j is range(2) 0 to 2 w/o 2 print(f"{i},{j}", end=" ") print() #tables of values # name1 data1,1 data1,2 data1,3 # name2 data2,1 ... # ... #e.g Country population by year #read names from the user DATA_POINTS = 4 #number of values of data in each "row" names = [] #initialization name = input("Enter a name (q to quit): ") while name != "q": #repeat (for each name the user enters) #add it to the list names.append(name) #get the data that goes with it for i in range(DATA_POINTS): value = float(input("Enter a number: ")) #next name = input("Enter a name (q to quit): ") print(names)