├── .gitattributes ├── Module 6 ├── Average_Steps_Taken6-12.py ├── AverageofNumbers6_6.py ├── File_Display6_1.py ├── File_Head_Display6_2.py ├── Golf_Scores6_10_1.py ├── Golf_Scores6_10_2.py ├── ItemCounter6-4.py ├── Line_Numbers6_3.py ├── Personal_Web_Page_Generator6-11.py ├── Random_Number_File_Reader6-8.py ├── Random_Number_File_Writer6-7.py ├── Sum_of_Numbers6-5.py ├── getStep.py ├── golf.txt ├── lineNumbers.txt ├── name_file.txt ├── names.txt ├── numbers.txt ├── randomNumber.txt ├── steps.txt └── webPage.html ├── Module2 ├── Compound Interest2_14.py ├── Distance Traveled 2_5.py ├── IngredientAdjuster2_10.py ├── Land Calculation 2_3.py ├── MaleandFemalePercentages2_11.py ├── Miles-per-Gallon 2_7.py ├── PlantingGrapevines2_13.py ├── Sales Tax 2_6.py ├── Stock Transaction Program2_12.py ├── TemperatureConverter 2_9.py ├── TipTaxTotal 2_8.py └── Total Purchase 2_4.py ├── Module3 ├── AgeClassifier3_3.py ├── Body_Mass_Index3_14.py ├── Book_Club_Points3_11.py ├── ColorMixer3_7.py ├── Day_of_the_Week3_1.py ├── February Days3_16.py ├── HotDogCalculator3_8.py ├── Magic Dates3_6.py ├── Mass and Weight3_5.py ├── Money_Counting_Game3_10.py ├── Restaurant Selector3_18.py ├── Roman Numerals3_4.py ├── Roulette_Wheel_Colors3_9.py ├── Shipping_Charges3_13.py ├── Software_Sales3_12.py ├── Time_Calculator3_16.py └── Wi-Fi_Diagnostic_Tree3_17.py ├── Module4 ├── Average Rainfall4_5.py ├── Budget_Analysis4_3.py ├── Bug Collector4_1.py ├── CalculatingFactorial4_12.py ├── Calories_Burned4_2.py ├── Celsius to Fahrenheit4_6.py ├── Distance_Traveled4_4.py ├── OceanLevel4_9.py ├── PenniesForPay4_7.py ├── Population4_13.py ├── Sum of Numbers4_8.py ├── Tuition_Increase4_10.py ├── Weight_Loss4_11.py └── nested_loops4_14.py ├── Module5 ├── Automobile_Costs5_4.py ├── Calories_Fat_Carbohydrates5_6.py ├── Falling_Distance5_13.py ├── Feet_to_Inches5_10.py ├── FutureValue5_19.py ├── Insurance5_3.py ├── Kilometer_Converte5_1.py ├── Kinetic_Energy5_14.py ├── Math_Quiz5_11.py ├── Maximum_of_Two_Values5_12.py ├── Monthly_Sales_Tax5_9.py ├── Odd_Even Counter5_16.py ├── Paint_Job_Estimator5_8.py ├── Prime_Number_List5-18.py ├── Prime_Numbers5_17.py ├── Property_tax5_5.py ├── Random_number5_20.py ├── Rock,Paper,Scissors5_21.py ├── Sales_Tax_Program_Refactoring5_2.py ├── Stadium_Seating5_7.py └── Test_Average_and_Grade5_15.py └── Module7 ├── 8_ball_responses.txt ├── BoyNames.txt ├── Charge_Account_Validation7_5.py ├── Driver’s_License_Exam7-7.py ├── GirlNames.txt ├── Larger_Than_n7-6.py ├── Lottery_Number_Generator7-3.py ├── Magic8Ball7_13.py ├── NameSearch7-8.py ├── Number_Analysis_Program7-4.py ├── Population Data7-9.py ├── RainfallStatistics7_2.py ├── Total_Sales7-1.py ├── USPopulation.txt ├── charge_accounts.txt └── user_answers.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Module 6/Average_Steps_Taken6-12.py: -------------------------------------------------------------------------------- 1 | # Average_Steps_Taken6-12 2 | 3 | # A Personal Fitness Tracker is a wearable device that tracks your physical 4 | # activity, calories burned, heart rate, sleeping patterns, and so on. 5 | # One common physical activity that most of these devices track 6 | # is the number of steps you take each day. 7 | # The steps.txt file contains the number of steps a person has taken each day 8 | # for a year. There are 365 lines in the file, and each line contains 9 | # the number of steps taken during a day. 10 | # (The first line is the number of steps taken on January 1st, 11 | # the second line is the number of steps taken on January 2nd, and so forth.) 12 | 13 | # Write a program that reads the file, then displays 14 | # the average number of steps taken for each month. 15 | # (The data is from a year that was not a leap year, so February has 28 days.) 16 | 17 | def getDays(month): 18 | if month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month==12: 19 | return 31 20 | elif month==2: 21 | return 28 22 | else: 23 | return 30 24 | 25 | def processMonth(month): 26 | days=getDays(month) 27 | total=0 28 | for day in range(1,days+1): 29 | line=int(file.readline().rstrip('\n')) 30 | total+=line 31 | average=total/days 32 | print(getMonth(month),'=',format(average,'.0f')) 33 | 34 | def getMonth(month): 35 | if month==1: 36 | return 'January' 37 | elif month==2: 38 | return 'February' 39 | elif month==3: 40 | return 'March' 41 | elif month==4: 42 | return 'April' 43 | elif month==5: 44 | return 'May' 45 | elif month==6: 46 | return 'June' 47 | elif month==7: 48 | return 'July' 49 | elif month==8: 50 | return 'August' 51 | elif month==9: 52 | return 'September' 53 | elif month==10: 54 | return 'October' 55 | elif month==11: 56 | return 'November' 57 | elif month==12: 58 | return 'December' 59 | 60 | 61 | def main(): 62 | 63 | for month in range(1,13): 64 | processMonth(month) 65 | 66 | 67 | file=open('steps.txt','r') 68 | 69 | main() 70 | -------------------------------------------------------------------------------- /Module 6/AverageofNumbers6_6.py: -------------------------------------------------------------------------------- 1 | # 6. Average of Numbers 2 | # Assume a file containing a series of integers is named numbers.txt 3 | # and exists on the computer’s disk. 4 | # Write a program that calculates the average of all the numbers 5 | # stored in the file. 6 | 7 | def main(): 8 | openFile=open('numbers.txt','r') 9 | total=0 10 | counter=0 11 | 12 | 13 | for line in openFile: 14 | counter+=1 15 | total+=int(line) 16 | average=total/counter 17 | print(line,end='') 18 | 19 | print('The total is',total) 20 | 21 | print('The average is',format(average,'.0f')) 22 | 23 | openFile.close() 24 | 25 | main() 26 | -------------------------------------------------------------------------------- /Module 6/File_Display6_1.py: -------------------------------------------------------------------------------- 1 | # File_Display6_1 2 | 3 | def main(): 4 | # Open the file. 5 | myfile=open('numbers.txt','r') 6 | # For each line the file: 7 | # Read line and display it. 8 | for line in myfile: 9 | number=int(line) 10 | print(number) 11 | 12 | 13 | # Close the file. 14 | main() 15 | -------------------------------------------------------------------------------- /Module 6/File_Head_Display6_2.py: -------------------------------------------------------------------------------- 1 | # File_Head_Display6_2 2 | 3 | # Write a program that asks the user for the name of a file. 4 | # The program should display only the first five lines of the file’s contents. 5 | # If the file contains less than five lines, 6 | # it should display the file’s entire contents. 7 | 8 | def main(): 9 | name_file=input('Enter the name of file: ') 10 | file=open(name_file,'r') 11 | 12 | for i in range(1,6): 13 | line=file.readline() 14 | if line=='': 15 | break 16 | print(line,end='') 17 | 18 | 19 | file.close() 20 | 21 | main() 22 | -------------------------------------------------------------------------------- /Module 6/Golf_Scores6_10_1.py: -------------------------------------------------------------------------------- 1 | # Golf_Scores6_10_1 2 | 3 | # The Springfork Amateur Golf Club has a tournament every weekend. 4 | # The club president has asked you to write two programs: 5 | 6 | # 1. A program that will read each player’s name and golf score 7 | # as keyboard input, then save these as records in a file named golf.txt. 8 | # Each record will have a field for the player’s name and a field for 9 | # the player’s score.) 10 | 11 | 12 | def main(): 13 | infile = open('golf.txt','w') 14 | name = input("Enter player's name: ") 15 | 16 | while name != '': 17 | score = input("Enter player's score: ") 18 | 19 | infile.write(name+'\n') 20 | infile.write(score+'\n') 21 | name = input("Enter player's name: ") 22 | 23 | 24 | infile.close() 25 | 26 | main() 27 | -------------------------------------------------------------------------------- /Module 6/Golf_Scores6_10_2.py: -------------------------------------------------------------------------------- 1 | # Golf_Scores6_10_2 2 | 3 | # The Springfork Amateur Golf Club has a tournament every weekend. 4 | # The club president has asked you to write two programs: 5 | 6 | # 2. A program that reads the records from the golf.txt 7 | # file and displays them. 8 | 9 | 10 | def main(): 11 | file=open('golf.txt','r') 12 | name=file.readline() 13 | print('Name','Score') 14 | print('-----','----') 15 | 16 | while name!= '': 17 | score=file.readline() 18 | print(name.rstrip('\n'),'-',score.rstrip('\n')) 19 | name=file.readline() 20 | 21 | 22 | file.close() 23 | main() 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Module 6/ItemCounter6-4.py: -------------------------------------------------------------------------------- 1 | # ItemCounter6-4 2 | 3 | # Assume a file containing a series of names (as strings) is named names.txt 4 | # and exists on the computer’s disk. 5 | # Write a program that displays the number of names that are stored in the file. 6 | # (Hint: Open the file and read every string stored in it. 7 | # Use a variable to keep a count of the number of items 8 | # that are read from the file.) 9 | 10 | def main(): 11 | contents=open('names.txt','r') 12 | line=contents.readline() 13 | counter=0 14 | 15 | while line!='': 16 | print(line,end='') 17 | line=contents.readline() 18 | counter+=1 19 | 20 | print('Total:',counter, 'names') 21 | 22 | 23 | main() 24 | 25 | 26 | -------------------------------------------------------------------------------- /Module 6/Line_Numbers6_3.py: -------------------------------------------------------------------------------- 1 | # Line_Numbers6_3 2 | # Write a program that asks the user for the name of a file. 3 | # The program should display the contents of the file with each line preceded 4 | # with a line number followed by a colon. 5 | # The line numbering should start at 1. 6 | # (lineNumbers.txt) 7 | 8 | def main(): 9 | fileName=input('Please enter a name a file: ') 10 | print() 11 | openFile=open(fileName,'r') 12 | line=openFile.readline() 13 | lineNumber=1 14 | 15 | while line!='': 16 | print(str(lineNumber)+':',line.rstrip('\n')) 17 | line=openFile.readline() 18 | lineNumber+=1 19 | 20 | 21 | main() 22 | -------------------------------------------------------------------------------- /Module 6/Personal_Web_Page_Generator6-11.py: -------------------------------------------------------------------------------- 1 | # Personal_Web_Page_Generator6-11 2 | 3 | # Write a program that asks the user for his or her name, 4 | # then asks the user to enter a sentence that describes himself or herself. 5 | # Here is an example of the program’s screen: 6 | # Enter your name: Julie Taylor 7 | # Describe yourself: I am a computer science major, a member of the Jazz club, 8 | # and I hope to work as a mobile app developer after I graduate. 9 | 10 | # Once the user has entered the requested input, 11 | # the program should create an HTML file, containing the input, 12 | # for a simple Web page. 13 | # Here is an example of the HTML content, using the sample input previously shown: 14 | # 15 | # 16 | # 17 | # 18 | #
19 | #

Julie Taylor

20 | #
21 | #
22 | # I am a computer science major, a member of the Jazz club, 23 | # and I hope to work as a mobile app developer after I graduate. 24 | #
25 | # 26 | # 27 | 28 | def main(): 29 | name=input('Enter your name: ') 30 | describe=input('Describe yourself: ') 31 | 32 | file=open('webPage.html','w') 33 | 34 | file.write('\n') 35 | file.write('\n') 36 | file.write('\n') 37 | file.write('\n') 38 | file.write('\t
\n') 39 | file.write('\t\t

'+name+'

\n') 40 | file.write('\t
\n') 41 | file.write('\t
\n') 42 | file.write('\t'+describe+'\n') 43 | file.write('\t
\n') 44 | file.write('\n') 45 | file.write('\n') 46 | 47 | file.close() 48 | 49 | main() 50 | 51 | -------------------------------------------------------------------------------- /Module 6/Random_Number_File_Reader6-8.py: -------------------------------------------------------------------------------- 1 | # Random_Number_File_Reader6-8 2 | 3 | # This exercise assumes you have completed Programming Exercise 7, 4 | # Random Number File Writer. 5 | # Write another program that reads the random numbers from the file, 6 | # displays the numbers, then displays the following data: 7 | # The total of the numbers 8 | # The number of random numbers read from the file 9 | 10 | def main(): 11 | file = open('randomNumber.txt','r') 12 | line = file.readline().rstrip('\n') 13 | total = 0 14 | counter = 0 15 | 16 | while line != '': 17 | total += int(line) 18 | counter += 1 19 | print(line) 20 | line = file.readline().rstrip('\n') 21 | 22 | print() 23 | print('The total is', total) 24 | print('The amount of random numbers is', counter) 25 | 26 | 27 | main() 28 | -------------------------------------------------------------------------------- /Module 6/Random_Number_File_Writer6-7.py: -------------------------------------------------------------------------------- 1 | # Random_Number_File_Writer6-7 2 | 3 | # Write a program that writes a series of random numbers to a file. 4 | # Each random number should be in the range of 1 through 500. 5 | # The application should let the user 6 | # specify how many random numbers the file will hold. 7 | 8 | import random 9 | 10 | def main(): 11 | num = int(input('How many numbers in range from 1 to 500 do you want to save: ')) 12 | randomFile = open('randomNumber.txt','w') 13 | 14 | for line in range(1, num+1): 15 | number = random.randint(1, 500) 16 | randomFile.write(str(number)+'\n') 17 | print(number) 18 | 19 | randomFile.close() 20 | 21 | main() 22 | -------------------------------------------------------------------------------- /Module 6/Sum_of_Numbers6-5.py: -------------------------------------------------------------------------------- 1 | # Sum_of_Numbers6-5 2 | 3 | # Assume a file containing a series of integers is named numbers.txt 4 | # and exists on the computer’s disk. 5 | # Write a program that reads all of the numbers 6 | # stored in the file and calculates their total. 7 | 8 | def main(): 9 | openFile=open('numbers.txt','r') 10 | total=0 11 | 12 | 13 | for line in openFile: 14 | total+=int(line) 15 | print(line,end='') 16 | 17 | print('The total is',total) 18 | 19 | openFile.close() 20 | 21 | main() 22 | -------------------------------------------------------------------------------- /Module 6/getStep.py: -------------------------------------------------------------------------------- 1 | 2 | import random 3 | def main(): 4 | fileStep=open('steps.txt','w') 5 | for day in range(1,366): 6 | step=getStep() 7 | fileStep.write(str(step)+'\n') 8 | fileStep.close() 9 | 10 | def getStep(): 11 | number=random.randint(1000,3000) 12 | return number 13 | 14 | 15 | main() 16 | -------------------------------------------------------------------------------- /Module 6/golf.txt: -------------------------------------------------------------------------------- 1 | Yana 2 | 10 3 | Andrew 4 | 11 5 | Vlad 6 | 12 7 | -------------------------------------------------------------------------------- /Module 6/lineNumbers.txt: -------------------------------------------------------------------------------- 1 | line one 2 | line two 3 | line three 4 | line four 5 | line five 6 | line six 7 | line seven 8 | line eight 9 | line nine 10 | line ten -------------------------------------------------------------------------------- /Module 6/name_file.txt: -------------------------------------------------------------------------------- 1 | line 2 | line 3 | line 4 | line 5 | line 6 | line 7 | line 8 | line 9 | line 10 | -------------------------------------------------------------------------------- /Module 6/names.txt: -------------------------------------------------------------------------------- 1 | Yana 2 | Lana 3 | Tata 4 | Jane 5 | Katya 6 | Lina 7 | Iana 8 | Cat 9 | Summer 10 | -------------------------------------------------------------------------------- /Module 6/numbers.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | -------------------------------------------------------------------------------- /Module 6/randomNumber.txt: -------------------------------------------------------------------------------- 1 | 112 2 | 96 3 | 7 4 | 398 5 | 293 6 | -------------------------------------------------------------------------------- /Module 6/steps.txt: -------------------------------------------------------------------------------- 1 | 1844 2 | 2846 3 | 1191 4 | 2605 5 | 1257 6 | 2170 7 | 2628 8 | 2936 9 | 2232 10 | 1392 11 | 2252 12 | 1165 13 | 2814 14 | 2562 15 | 2177 16 | 2543 17 | 1429 18 | 2081 19 | 2359 20 | 2077 21 | 2697 22 | 2372 23 | 2675 24 | 2637 25 | 2915 26 | 1358 27 | 2623 28 | 2919 29 | 1961 30 | 2171 31 | 1638 32 | 2507 33 | 1860 34 | 2507 35 | 2751 36 | 1823 37 | 1346 38 | 2808 39 | 1671 40 | 1454 41 | 2037 42 | 2759 43 | 2911 44 | 2985 45 | 1999 46 | 2884 47 | 1078 48 | 1277 49 | 2351 50 | 1620 51 | 1946 52 | 1722 53 | 2769 54 | 2896 55 | 2199 56 | 1034 57 | 2859 58 | 1573 59 | 1103 60 | 2886 61 | 2306 62 | 2195 63 | 2304 64 | 2672 65 | 2976 66 | 1497 67 | 1937 68 | 1792 69 | 2531 70 | 1639 71 | 2097 72 | 1473 73 | 1652 74 | 1266 75 | 1882 76 | 2575 77 | 2777 78 | 2170 79 | 1199 80 | 2728 81 | 2191 82 | 2062 83 | 1803 84 | 1859 85 | 1117 86 | 1823 87 | 1472 88 | 2663 89 | 2245 90 | 1744 91 | 1224 92 | 1102 93 | 2804 94 | 1133 95 | 1096 96 | 1962 97 | 2557 98 | 1400 99 | 1528 100 | 1533 101 | 1491 102 | 2365 103 | 1667 104 | 1958 105 | 2297 106 | 2098 107 | 1765 108 | 2953 109 | 1596 110 | 2927 111 | 2942 112 | 2406 113 | 1983 114 | 2421 115 | 1155 116 | 1116 117 | 2625 118 | 1992 119 | 2343 120 | 2575 121 | 2223 122 | 1266 123 | 1375 124 | 2062 125 | 1844 126 | 1877 127 | 2871 128 | 1103 129 | 1071 130 | 2064 131 | 2114 132 | 1259 133 | 1560 134 | 1228 135 | 2507 136 | 1345 137 | 2861 138 | 1071 139 | 1318 140 | 2295 141 | 1135 142 | 2721 143 | 2197 144 | 2237 145 | 1319 146 | 2764 147 | 2855 148 | 2645 149 | 2990 150 | 2503 151 | 1754 152 | 2882 153 | 1054 154 | 2445 155 | 1326 156 | 2458 157 | 1267 158 | 2646 159 | 1769 160 | 2870 161 | 2422 162 | 1628 163 | 1107 164 | 2191 165 | 1170 166 | 1648 167 | 2433 168 | 1548 169 | 2245 170 | 2184 171 | 1806 172 | 2622 173 | 2401 174 | 2296 175 | 1045 176 | 2566 177 | 2208 178 | 1749 179 | 1078 180 | 2061 181 | 2903 182 | 1440 183 | 1747 184 | 2029 185 | 1084 186 | 2318 187 | 1536 188 | 2625 189 | 1369 190 | 1837 191 | 1961 192 | 1516 193 | 1094 194 | 1458 195 | 1469 196 | 1818 197 | 2794 198 | 1466 199 | 2810 200 | 1595 201 | 2863 202 | 1613 203 | 1088 204 | 2180 205 | 2061 206 | 1079 207 | 2125 208 | 2856 209 | 1441 210 | 2561 211 | 2268 212 | 1881 213 | 1875 214 | 1791 215 | 2508 216 | 2076 217 | 2497 218 | 1823 219 | 1269 220 | 2446 221 | 1349 222 | 1575 223 | 2687 224 | 2562 225 | 1664 226 | 1145 227 | 1426 228 | 2596 229 | 1123 230 | 2411 231 | 2079 232 | 2835 233 | 2632 234 | 2801 235 | 1372 236 | 2266 237 | 1370 238 | 1956 239 | 1513 240 | 2341 241 | 2628 242 | 2098 243 | 1045 244 | 1629 245 | 1276 246 | 1824 247 | 2444 248 | 2745 249 | 1071 250 | 2564 251 | 2563 252 | 1330 253 | 2391 254 | 1575 255 | 2884 256 | 2010 257 | 2389 258 | 2503 259 | 1280 260 | 1872 261 | 2914 262 | 1408 263 | 2456 264 | 1346 265 | 1460 266 | 1120 267 | 2088 268 | 1410 269 | 2789 270 | 1718 271 | 2830 272 | 2011 273 | 1328 274 | 2188 275 | 2800 276 | 1687 277 | 2233 278 | 1020 279 | 1812 280 | 2121 281 | 1573 282 | 1253 283 | 1719 284 | 1879 285 | 2640 286 | 1326 287 | 2107 288 | 1225 289 | 1078 290 | 1297 291 | 1098 292 | 2399 293 | 2599 294 | 1138 295 | 1665 296 | 1533 297 | 2000 298 | 2859 299 | 1411 300 | 1049 301 | 2858 302 | 2977 303 | 2190 304 | 2152 305 | 1887 306 | 1305 307 | 2661 308 | 2672 309 | 2163 310 | 2502 311 | 1337 312 | 1034 313 | 2291 314 | 2804 315 | 1404 316 | 1672 317 | 2913 318 | 2144 319 | 1615 320 | 1561 321 | 2373 322 | 1624 323 | 1446 324 | 1010 325 | 1656 326 | 1098 327 | 2324 328 | 1069 329 | 1277 330 | 1138 331 | 1563 332 | 1567 333 | 1545 334 | 1967 335 | 1017 336 | 2960 337 | 2177 338 | 1338 339 | 2676 340 | 2496 341 | 1303 342 | 1381 343 | 2011 344 | 2168 345 | 1082 346 | 1155 347 | 2880 348 | 2479 349 | 1352 350 | 2257 351 | 2493 352 | 2925 353 | 2665 354 | 2855 355 | 1012 356 | 2145 357 | 2850 358 | 2301 359 | 2434 360 | 1143 361 | 2183 362 | 2506 363 | 1622 364 | 2190 365 | 2451 366 | -------------------------------------------------------------------------------- /Module 6/webPage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 |

Yana

7 |
8 |
9 | I am a computer science major, a member of the Jazz club, and I hope to work as a mobile app developer after I graduate. 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /Module2/Compound Interest2_14.py: -------------------------------------------------------------------------------- 1 | # Compound Interest2_14 2 | 3 | def main(): 4 | # ask user to enter and assign to: 5 | # originaly_deposit 6 | # annual_rate 7 | # compound_per_year 8 | # years_left 9 | originaly_deposit=float(input('Enter originaly deposit amount of money $ ')) 10 | annual_rate=float(input('Enter originaly deposit annual rate % ')) 11 | compound_per_year=float(input('Enter times compound per year: ')) 12 | years_left=float(input('Enter number of years account will left money ')) 13 | 14 | # calculate amount_after by formula. 15 | # A=P(1/rn)**nt 16 | amount_after=originaly_deposit*(1+annual_rate/compound_per_year)**(compound_per_year*years_left) 17 | 18 | # display result. 19 | print('Amount of money in the account after the specified number of years $',format(amount_after,'.2f'),sep='') 20 | main() 21 | -------------------------------------------------------------------------------- /Module2/Distance Traveled 2_5.py: -------------------------------------------------------------------------------- 1 | # Distance Traveled 2_5 2 | 3 | def main(): 4 | 5 | speed=70 6 | time1=6 7 | time2=10 8 | time3=15 9 | 10 | # calculate distance=speed*time 11 | # car speed=70mph/h 12 | distance1=speed*time1 13 | distance2=speed*time2 14 | distance3=speed*time3 15 | 16 | # display distance in 6 hr/10hr/15hr 17 | print('Distance the car will travel in 6 hours',distance1,'miles') 18 | print('Distance the car will travel in 10 hours',distance2,'miles') 19 | print('Distance the car will travel in 15 hours',distance3,'miles') 20 | 21 | main() 22 | -------------------------------------------------------------------------------- /Module2/IngredientAdjuster2_10.py: -------------------------------------------------------------------------------- 1 | #IngredientAdjuster2_10 2 | 3 | def main(): 4 | # ask the user how many cookies he or she wants to make. 5 | x=float(input('How many cookies do you want to make? ')) 6 | 7 | # assign variables to sugar,butter,flour. 8 | sugar=1.5 9 | butter=1 10 | flour=2.75 11 | 12 | # calculate number of cups each ingredients for one cookies. 13 | sugar48=1.5/48 14 | butter48=1/48 15 | flour48=2.75/48 16 | 17 | # calculate number of cups each ingredients for the specified number of cookies. 18 | sugar_x=sugar48*x 19 | butter_x=butter48*x 20 | flour_x=flour48*x 21 | 22 | # print result. 23 | print('You needed this ingredients:') 24 | print('sugar:',format(sugar_x,'.2f'),'cups') 25 | print('butter:',format(butter_x,'.2f'),'cups') 26 | print('flour:',format(flour_x,'.2f'),'cups') 27 | 28 | main() 29 | 30 | -------------------------------------------------------------------------------- /Module2/Land Calculation 2_3.py: -------------------------------------------------------------------------------- 1 | #Land Calculation 2_3 2 | 3 | def main(): 4 | one_acre=43.560 5 | 6 | #ask user to enter total square feet 7 | total_squareFeet=float(input('Enter totta in square feet ')) 8 | 9 | #calculate number the number of acres 10 | total_acres=total_squareFeet/43560 11 | # print result 12 | print('Number the number of acres:',format(total_acres,'.2f'),'acre') 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /Module2/MaleandFemalePercentages2_11.py: -------------------------------------------------------------------------------- 1 | # Male and Female Percentages 2 | 3 | def main(): 4 | # ask to enter the namber of females and males. 5 | females=int(input('How many females in your class? ')) 6 | males=int(input('How many males in your class? ')) 7 | 8 | # calculate the total of females and males. 9 | total=females+males 10 | 11 | # calculate the percentage females and males. 12 | percent_females=females/total*100 13 | percent_males=males/total*100 14 | 15 | # display the percentage of males and females in the class. 16 | print('The percentage of females in your class is ',format(percent_females,'.0f')) 17 | print('The percentage of males in your class is ',format(percent_males,'.0f')) 18 | 19 | main() 20 | -------------------------------------------------------------------------------- /Module2/Miles-per-Gallon 2_7.py: -------------------------------------------------------------------------------- 1 | # Miles-per-Gallon 2_7 2 | 3 | def main(): 4 | # get number of miles driven 5 | # get the gallons of gas used 6 | miles_driven=float(input('Enter miles of driven ')) 7 | gas_used=float(input('Enter the gallons of gas used ')) 8 | 9 | # calculate MPG(miles per gallon) by formula 10 | # mpg=miles dfiven/gallons of gas used 11 | mpg=miles_driven/gas_used 12 | 13 | # display result 14 | print('Miles per gallon is',format(mpg,'.2f')) 15 | 16 | main() 17 | -------------------------------------------------------------------------------- /Module2/PlantingGrapevines2_13.py: -------------------------------------------------------------------------------- 1 | # PlantingGrapevines2_13 2 | 3 | def main(): 4 | # ask to enter lenght_row, space_for_assembly,space_between_vines. 5 | lenght_row=float(input('Enter lenght of the row in feet: ')) 6 | space_for_assembly=float(input('Enter amount of space used by an end-post assembly: ')) 7 | space_between_vines=float(input('Enter amount of space between the vines, in feet: ')) 8 | 9 | # calculate by formula V=R-2ES. 10 | number_grapevines=lenght_row-2*(space_for_assembly*space_between_vines) 11 | 12 | # dispaly the result #The number of grapevines that will fit in the row. 13 | print('The number of grapevines that will fit in the row: ',format(number_grapevines,'.0f')) 14 | main() 15 | -------------------------------------------------------------------------------- /Module2/Sales Tax 2_6.py: -------------------------------------------------------------------------------- 1 | # Sales Tax 2_6 2 | 3 | def main(): 4 | # ask user to enter the amount of purchase 5 | amount_purchase=float(input('Enter the amount of purchase: ')) 6 | 7 | # calculate 1.state_tax, 2.county_tax, 3.total_salesTax, 4.total_sale 8 | state_tax=amount_purchase*0.05 9 | county_tax=amount_purchase*0.025 10 | total_salesTax=state_tax+county_tax 11 | total_sale=total_salesTax+amount_purchase 12 | 13 | # display result 14 | print('State Tax: $',format(state_tax,',.2f'),sep='') 15 | print('County Tax: $',format(county_tax,',.2f'),sep='') 16 | print('Tatal Sales Tax: $',format(total_salesTax,',.2f'),sep='') 17 | print('Total of the sale: $',format(total_sale,',.2f'),sep='') 18 | 19 | main() 20 | -------------------------------------------------------------------------------- /Module2/Stock Transaction Program2_12.py: -------------------------------------------------------------------------------- 1 | # Stock Transaction Program2_12 2 | 3 | def main(): 4 | # calculate purchased stock. 5 | paid_for=2000.00*42 6 | comm1=paid_for*3/100 7 | 8 | # calculate sold stock. 9 | sold_for=2000*42.75 10 | comm2=sold_for*3/100 11 | total_comm=comm1+comm2 12 | 13 | # calculate profit. 14 | profit=(sold_for-paid_for)-total_comm 15 | 16 | # display the result. 17 | print('The amount of money paid for the stock $:',format(paid_for,'.2f'),sep='') 18 | print('The amount of commission when he bought: the stock $:',format(comm1,'.2f'),sep='') 19 | print('The amount for which sold the stock $:',format(sold_for,'.2f'),sep='') 20 | print('The amount of commission paid when he sold the stock $:',format(comm2,'.2f'),sep='') 21 | print('Profit is: $ ',format(profit,'.2f'),sep='') 22 | 23 | main() 24 | -------------------------------------------------------------------------------- /Module2/TemperatureConverter 2_9.py: -------------------------------------------------------------------------------- 1 | #TemperatureConverter 2_9 2 | 3 | def main(): 4 | 5 | # ask to enter Celsius t 6 | Celsius=float(input('Enter the teperature in C ')) 7 | # calculate by formula 8 | # F=C*1.8+32 9 | Fahrenheit=Celsius*1.8+32 10 | #print(Temperature in Fahrenheit) 11 | print('Temperature in F is',Fahrenheit) 12 | 13 | main() 14 | -------------------------------------------------------------------------------- /Module2/TipTaxTotal 2_8.py: -------------------------------------------------------------------------------- 1 | # TipTaxTotal 2_8 2 | 3 | def main(): 4 | 5 | # get the price for meal, assign to price_meal 6 | price_meal=float(input('Enter the price for meal: ')) 7 | 8 | # calculate amount of tip - price_meal*0.08 9 | # calculate tax - price_meal*0.07 10 | # calculate total_amount - price_meal+tip+tax 11 | tip=price_meal*0.08 12 | tax=price_meal*0.07 13 | total_amount=price_meal+tip+tax 14 | 15 | # display - Price for meal, Tip, Tax, Total amount 16 | print('Tip 8%: $',format(tip,'.2f'),sep='') 17 | print('Tax: $',format(tax,'.2f'),sep='') 18 | print('Total amount: $',format(total_amount,'.2f'),sep='') 19 | 20 | main() 21 | -------------------------------------------------------------------------------- /Module2/Total Purchase 2_4.py: -------------------------------------------------------------------------------- 1 | # Total Purchase 2_4 2 | 3 | def main(): 4 | #get price for each of 5 items 5 | item1=float(input('Enter the price for item1 ')) 6 | item2=float(input('Enter the price for item2 ')) 7 | item3=float(input('Enter the price for item3 ')) 8 | item4=float(input('Enter the price for item4 ')) 9 | item5=float(input('Enter the price for item5 ')) 10 | 11 | #calculate subtotal of 5 items 12 | subtotal=item1+item2+item3+item4+item5 13 | 14 | #calculate tax susbtotal*0.07 15 | tax=subtotal*0.07 16 | 17 | #calculate total subtotal+tax 18 | total=subtotal+tax 19 | 20 | #print result 21 | print('Subtotal: $',format(subtotal,'.2f'),sep='') 22 | print('Tax: $',format(tax,'.2f'),sep='') 23 | print('Total: $',format(total,'.2f'),sep='') 24 | 25 | 26 | main() 27 | -------------------------------------------------------------------------------- /Module3/AgeClassifier3_3.py: -------------------------------------------------------------------------------- 1 | # AgeClassifier3_3 2 | 3 | #Write a program that asks the user to enter a person’s age. 4 | #The program should display a message indicating 5 | #whether the person is an infant, a child, a teenager, or an adult. 6 | #Following are the guidelines: 7 | #If the person is 1 year old or less, he or she is an infant. 8 | #If the person is older than 1 year, but younger than 13 years, he or she is a child. 9 | #If the person is at least 13 years old, but less than 20 years old, he or she is a teenager. 10 | #If the person is at least 20 years old, he or she is an adult. 11 | 12 | def main(): 13 | # start program 14 | age=int(input('What is your age? ')) 15 | if age<=1: 16 | print('You are an infant ') 17 | else: 18 | if age>1 and age<13: 19 | print('You are a child ') 20 | else: 21 | if age>13 and age<20: 22 | print('You are a teenager ') 23 | else: 24 | print('You are an adult') 25 | main() 26 | # end program 27 | -------------------------------------------------------------------------------- /Module3/Body_Mass_Index3_14.py: -------------------------------------------------------------------------------- 1 | # Body_Mass_Index3_14 2 | 3 | # Write a program that calculates and displays a person’s body mass index (BMI). 4 | # The BMI is often used to determine whether a person is overweight or underweight 5 | # for his or her height. 6 | 7 | # A person’s BMI is calculated with the following formula: 8 | # BMI=weight×703/height2 9 | # where weight is measured in pounds and height is measured in inches. 10 | 11 | # The program should ask the user to enter his or her weight and height, 12 | # then display the user’s BMI. 13 | 14 | # The program should also display a message indicating whether the person 15 | # has optimal weight, is underweight, or is overweight. 16 | # A person’s weight is considered to be optimal 17 | # if his or her BMI is between 18.5 and 25. 18 | # If the BMI is less than 18.5, the person is considered to be underweight. 19 | # If the BMI value is greater than 25, the person is considered to be overweight 20 | 21 | 22 | def main(): 23 | # ask user to enter weight in pounds and height in inches. 24 | weight=float(input('Enter your weight in pounds: ')) 25 | height=float(input('Enter your height in inches: ')) 26 | 27 | # calculate BMI by formula. 28 | BMI=weight*703/height**2 29 | if BMI>=18.5 and BMI<=25: 30 | print('Your weight is optimal!') 31 | elif BMI<18.5: 32 | print('Your weight is underweight!') 33 | elif BMI>25: 34 | print('Your weight is overweight!') 35 | 36 | main() 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Module3/Book_Club_Points3_11.py: -------------------------------------------------------------------------------- 1 | # Book_Club_Points3_11 2 | # Booksellers has a book club that awards points 3 | # to its customers based on the number of books purchased each month. 4 | # The points are awarded as follows: 5 | # If a customer purchases 0 books, he or she earns 0 points. 6 | # If a customer purchases 2 books, he or she earns 5 points. 7 | # If a customer purchases 4 books, he or she earns 15 points. 8 | # If a customer purchases 6 books, he or she earns 30 points. 9 | # If a customer purchases 8 or more books, he or she earns 60 points. 10 | # Write a program that asks the user to enter the number of books 11 | # that he or she has purchased this month, 12 | # then displays the number of points awarded. 13 | 14 | def main(): 15 | books_purchased=int(input('Enter the number of book that you purchased this month: ')) 16 | if books_purchased<=1: 17 | points=0 18 | print('Number of points awarded:',points) 19 | elif books_purchased>=2 and books_purchased<=3: 20 | points=5 21 | print('Number of points awarded:',points) 22 | elif books_purchased>=4 and books_purchased<=5: 23 | points=15 24 | print('Number of points awarded:',points) 25 | elif books_purchased>=6 and books_purchased<=7: 26 | points=30 27 | print('Number of points awarded:',points) 28 | else: 29 | points=60 30 | print('Number of points awarded:',points) 31 | main() 32 | -------------------------------------------------------------------------------- /Module3/ColorMixer3_7.py: -------------------------------------------------------------------------------- 1 | # ColorMixer3_7 2 | 3 | # The colors red, blue, and yellow are known as the primary colors 4 | # because they cannot be made by mixing other colors. 5 | # When you mix two primary colors, you get a secondary color, as shown here: 6 | # When you mix red and blue, you get purple. 7 | # When you mix red and yellow, you get orange. 8 | # When you mix blue and yellow, you get green. 9 | # Design a program that prompts the user to enter 10 | # the names of two primary colors to mix. 11 | # If the user enters anything other than “red,” “blue,” or “yellow,” 12 | # the program should display an error message. 13 | # Otherwise, the program should display the name of the secondary color 14 | # that results. 15 | 16 | def main(): 17 | color=input('Enter one of the three colors: red, blue, yellow: ') 18 | color2=input('Enter one of the three colors: red, blue, yellow: ') 19 | if color=='red' and color2=='blue' or\ 20 | color=='blue' and color2=='red': 21 | print('You get the purple color') 22 | elif color=='yellow' and color2=='red' or\ 23 | color=='red' and color2=='yellow': 24 | print('You get the orange color') 25 | elif color=='blue' and color2=='yellow' or\ 26 | color=='yellow' and color2=='blue': 27 | print('You get the green color!') 28 | else: 29 | print(color2) 30 | 31 | main() 32 | -------------------------------------------------------------------------------- /Module3/Day_of_the_Week3_1.py: -------------------------------------------------------------------------------- 1 | #Day_of_the_Week3_1 2 | def main(): 3 | #start program 4 | 5 | # assign all variables for numbers from 1-7 6 | Monday=1 7 | Tuesday=2 8 | Wednesday=3 9 | Thursday=4 10 | Friday=5 11 | Saturday=6 12 | Sunday=7 13 | # ask user to enter number in the range from 1 to 7 14 | today_day=int(input('Enter the number in the range from 1 to 7: ')) 15 | # determines corresponding day for number that user entered 16 | if today_day==1: 17 | print('Monday') 18 | elif today_day==2: 19 | print('Tuesday') 20 | elif today_day==3: 21 | print('Wedneday') 22 | elif today_day==4: 23 | print('Thursday') 24 | elif today_day==5: 25 | print('Friday') 26 | elif today_day==6: 27 | print('Saturday') 28 | elif today_day==7: 29 | print('Sunday') 30 | else: 31 | print('Error message') 32 | 33 | #end program 34 | main() 35 | -------------------------------------------------------------------------------- /Module3/February Days3_16.py: -------------------------------------------------------------------------------- 1 | # February Days3_16 2 | # The month of February normally has 28 days. 3 | # But if it is a leap year, February has 29 days. 4 | 5 | # Write a program that asks the user to enter a year. 6 | # The program should then display the number of days in February that year. 7 | # Use the following criteria to identify leap years: 8 | # 1. Determine whether the year is divisible by 100. 9 | # If it is, then it is a leap year if and only if it is also divisible by 400. 10 | # For example, 2000 is a leap year, but 2100 is not. 11 | 12 | # 2. If the year is not divisible by 100, then it is a leap year 13 | # if and only if it is divisible by 4. 14 | # For example, 2008 is a leap year, but 2009 is not. 15 | # Here is a sample run of the program: 16 | # Enter a year: 2008 In 2008 February has 29 days. 17 | 18 | def main(): 19 | # ask user to enter a year. 20 | year=int(input('Enter a year: ')) 21 | 22 | if year%100==0 and year%400==0: 23 | print('It is a leap year!','In',year,'February has 29 days.') 24 | elif year%100!=0 and year%4==0: 25 | print('It is a leap year!','In',year,'February has 29 days.') 26 | else: 27 | print('It is not a leap year!') 28 | 29 | main() 30 | -------------------------------------------------------------------------------- /Module3/HotDogCalculator3_8.py: -------------------------------------------------------------------------------- 1 | #hot dogs=10 in pack 2 | #buns=8 in pack 3 | #Enter number of people attending the cookout 4 | #Enter number of hot dogs each person will be given 5 | 6 | #Display: 7 | #The minimum number of packages of hot dogs required MIN_HOTDOGS 8 | #The minimum number of packages of hot dog buns required 9 | #The number of hot dogs that will be left over 10 | #The number of hot dog buns that will be left over 11 | 12 | number_people=int(input('Enter number of people attending the cookout ')) 13 | number_hotdogs=int(input('Enter number of hot dogs each person will be given ')) 14 | 15 | total_hotdogs=number_people*number_hotdogs 16 | number_hotdogs_left=10-total_hotdogs%10 17 | if number_hotdogs_left==10: 18 | number_hotdogs_left=0 19 | number_buns_left=8-total_hotdogs%8 20 | if number_buns_left==8: 21 | number_buns_left=0 22 | 23 | number_hotdogs_pack=total_hotdogs//10 24 | if number_hotdogs_left>0: 25 | number_hotdogs_pack = number_hotdogs_pack+1 26 | 27 | number_buns_pack=total_hotdogs//8 28 | if number_buns_left>0: 29 | number_buns_pack = number_buns_pack+1 30 | 31 | 32 | print('The minimum number of packages of hot dogs required',number_hotdogs_pack) 33 | print('The minimum number of packages of hot dog buns required',number_buns_pack) 34 | print('The number of hot dogs that will be left over',number_hotdogs_left) 35 | print('The number of hot dog buns that will be left over',number_buns_left) 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Module3/Magic Dates3_6.py: -------------------------------------------------------------------------------- 1 | # Magic Dates3_6 2 | # The date June 10, 1960, 3 | # is special because when it is written in the following format, 4 | # the month times the day equals the year: 6/10/60 5 | # Design a program that asks the user 6 | # to enter a month (in numeric form), a day, and a two-digit year. 7 | # The program should then determine whether 8 | # the month times the day equals the year. 9 | # If so, it should display a message saying the date is magic. 10 | # Otherwise, it should display a message saying the date is not magic 11 | 12 | 13 | def main(): 14 | 15 | month=int(input('Enter month in numeric form: ')) 16 | day=int(input('Enter date of day: ')) 17 | year=int(input('Enter two-digit year: ')) 18 | magic=month*day 19 | if magic==year: 20 | print('The date is magic') 21 | else: 22 | print('The date is not magic') 23 | main() 24 | -------------------------------------------------------------------------------- /Module3/Mass and Weight3_5.py: -------------------------------------------------------------------------------- 1 | # Mass and Weight3_5 2 | 3 | # Scientists measure an object’s mass in kilograms and its weight in newtons. 4 | # If you know the amount of mass of an object 5 | # in kilograms, you can calculate its weight in newtons 6 | # with the following formula: weight=mass×9.8 7 | # Write a program that asks the user to enter an object’s mass, 8 | # then calculates its weight. 9 | # If the object weighs more than 500 newtons, 10 | # display a message indicating that it is too heavy. 11 | # If the object weighs less than 100 newtons, 12 | # display a message indicating that it is too light. 13 | 14 | def main(): 15 | # start program 16 | 17 | mass=float(input('Enter mass in kilograms: ')) 18 | weight=mass*9.8 19 | if weight>500: 20 | print(weight,'newtons','- that it is too heavy') 21 | else: 22 | if weight<100: 23 | print(weight,'newtons','- is too light') 24 | 25 | # end program 26 | main() 27 | -------------------------------------------------------------------------------- /Module3/Money_Counting_Game3_10.py: -------------------------------------------------------------------------------- 1 | #Money_Counting_Game3_10 2 | # That gets the user to enter the number of coins 3 | # required to make exactly one dollar. 4 | # The program should prompt the user to enter the number 5 | # of pennies, nickels, dimes, and quarters. 6 | # If the total value of the coins entered is equal to one dollar, 7 | # the program should congratulate the user for winning the game. 8 | # Otherwise, the program should display a message indicating whether 9 | # the amount entered was more than or less than one dollar. 10 | 11 | def main(): 12 | pennies=int(input('Enter the number of pennies: ')) 13 | nickels=int(input('Enter the number of nickels: ')) 14 | dimes=int(input('Enter the number of dimes: ')) 15 | quaters=int(input('Enter the number of quaters: ')) 16 | 17 | pennies=pennies*1 18 | nickels=nickels*5 19 | dimes=dimes*10 20 | quaters=quaters*25 21 | 22 | dollar=pennies+nickels+dimes+quaters 23 | 24 | if dollar==100: 25 | print('Congratulations - you entered exact amount for one dollar! ') 26 | elif dollar>100: 27 | print('The amount was enetered more than one dollar...Try again! ') 28 | else: 29 | print('The amount was entered less than one dollar ...Try again! ') 30 | 31 | main() 32 | -------------------------------------------------------------------------------- /Module3/Restaurant Selector3_18.py: -------------------------------------------------------------------------------- 1 | # Restaurant_Selector3_18 2 | def main(): 3 | 4 | vegeterian=str(input('Is any one in your party a vegetarian? ')) 5 | vegan=str(input('Is anyone in your party a vegan? ')) 6 | gluten_free=str(input('Is anyone in your party gluten_free? ')) 7 | 8 | rstrnt1="Joe's Gourmet Burgers" 9 | # veget=no, vegan=no, glu=no 10 | rstrnt2="Main Street Pizza Company" 11 | # veget=yes, vegan=no ,glu=yes 12 | rstrnt3="Corner Cafe" 13 | # veget=yes, vegan=yes, glu=yes 14 | rstrnt4="Mama's Fine Italian" 15 | # veget=yes, vegan=no, glu=no 16 | rstrnt5="The Chef's Kitchen" 17 | #veget=yes, vegan=yes, glu=yes 18 | 19 | print('Here are your restaraunt choice: ') 20 | 21 | 22 | if vegeterian=='yes' and vegan=='yes' and gluten_free=='yes': 23 | print(rstrnt3,'\n',rstrnt5) 24 | 25 | if vegeterian=='yes' and vegan=='yes' and gluten_free=='no': 26 | print(rstrnt3,'\n',rstrnt5) 27 | 28 | if vegeterian=='yes' and vegan=='no' and gluten_free=='yes': 29 | print(rstrnt2,'\n',rstrnt3,'\n',rstrnt5) 30 | 31 | if vegeterian=='no' and vegan=='yes' and gluten_free=='yes': 32 | print(rstrnt3,'\n',rstrnt3) 33 | 34 | if vegeterian=='no' and vegan=='yes' and gluten_free=='no': 35 | print(rstrnt3,'\n',rstrnt5) 36 | 37 | if vegeterian=='no' and vegan=='no' and gluten_free=='yes': 38 | print(rstrnt2,'\n',rstrnt3,'\n',rstrnt5) 39 | 40 | if vegeterian=='yes' and vegan=='no' and gluten_free=='no': 41 | print(rstrnt2,'\n',rstrnt3,'\n',rstrnt4,'\n',rstrnt5) 42 | 43 | if vegeterian=='no' and vegan=='no' and glute_freen=='no': 44 | print(rstrnt1,'\n',rstrnt2,'\n',rstrnt3,'\n',rstrnt4,'\n',rstrnt5) 45 | 46 | main() 47 | -------------------------------------------------------------------------------- /Module3/Roman Numerals3_4.py: -------------------------------------------------------------------------------- 1 | # Roman Numerals3_4 2 | 3 | # Write a program that prompts the user to enter 4 | # a number within the range of 1 through 10. 5 | # The program should display the Roman numeral version of that number. 6 | # If the number is outside the range of 1 through 10, the program should display an error message. 7 | # The following table shows the Roman numerals for the numbers 1 through 10: 8 | # NumberRoman Numeral 9 | 10 | def main(): 11 | # start program 12 | I=1 13 | II=2 14 | III=3 15 | IV=4 16 | V=5 17 | VI=6 18 | VII=7 19 | VIII=8 20 | IX=9 21 | X=10 22 | number=int(input('Enter number within the range of 1 through 10: ')) 23 | if number ==1: 24 | print('Roman Numeral is I') 25 | elif number==2: 26 | print('Roman Numeral is II') 27 | elif number==3: 28 | print('Roman Numeral is III') 29 | elif number==4: 30 | print('Roman Numeral is IV') 31 | elif number==5: 32 | print('Roman Numeral is V') 33 | elif number==6: 34 | print('Roman Numeral is VI') 35 | elif number==7: 36 | print('Roman Numeral is VII') 37 | elif number==8: 38 | print('Roman Numeral is VIII') 39 | elif number==9: 40 | print('Roman Numeral is IX') 41 | elif number==10: 42 | print('Roman Numeral is X') 43 | else: 44 | print('error message') 45 | 46 | main() 47 | # end program 48 | -------------------------------------------------------------------------------- /Module3/Roulette_Wheel_Colors3_9.py: -------------------------------------------------------------------------------- 1 | # Roulette_Wheel_Colors3_9 2 | 3 | def main(): 4 | pockets_number=int(input('Enter number from 0 to 36: ')) 5 | 6 | if pockets_number==0: 7 | print('Pockets are green') 8 | elif pockets_number>=1 and pockets_number<=10: 9 | if pockets_number%2==0: 10 | print('Pockets are black!') 11 | else: 12 | print('Pockets red') 13 | elif pockets_number>=11 and pockets_number<=18: 14 | if pockets_number%2==0: 15 | print('Pockets are red!') 16 | else: 17 | print('Pockets are black') 18 | elif pockets_number>=19 and pockets_number<=28: 19 | if pockets_number%2==0: 20 | print('Pockets are black!') 21 | else: 22 | print('Pockets are red') 23 | elif pockets_number>=29 and pockets_number<=36: 24 | if pockets_number%2==0: 25 | print('Pockets are red!') 26 | else: 27 | print('Pockets are black!') 28 | else: 29 | print('You should enter number from 0 to 36 ') 30 | 31 | 32 | 33 | main() 34 | -------------------------------------------------------------------------------- /Module3/Shipping_Charges3_13.py: -------------------------------------------------------------------------------- 1 | # Shipping_Charges3_13 2 | # Shipping Company charges the following rates: 3 | # Weight of Package Rate per Pound 2 pounds or less $1.50 4 | # Over 2 pounds but not more than 6 pounds $3.00 5 | # Over 6 pounds but not more than 10 pounds$4.00 6 | # Over 10 pounds $4.75 7 | # Write a program that asks the user to enter the weight of a package 8 | # then displays the shipping charges. 9 | 10 | 11 | 12 | def main(): 13 | 14 | weight_packages=float(input('Enter the weight of a package in lb: ')) 15 | 16 | if weight_packages >=0 and weight_packages<=2: 17 | price_charges=1.5 18 | elif weight_packages >=2 and weight_packages<=6: 19 | price_charges=3.00 20 | elif weight_packages >=6 and weight_packages<=10: 21 | price_charges=4.00 22 | else: 23 | price_charges=4.75 24 | 25 | shipping_charges=weight_packages*price_charges 26 | print('Shipping charges: $',format(shipping_charges,'.2f'),sep='') 27 | 28 | main() 29 | -------------------------------------------------------------------------------- /Module3/Software_Sales3_12.py: -------------------------------------------------------------------------------- 1 | # Software_Sales3_12 2 | 3 | # A software company sells a package that retails for $99. 4 | # Quantity discounts are given according to the following table: 5 | # Quantity Discount 10–19 10% 20–49 20% 50–99 30% 100 or more40% 6 | # Write a program that asks the user to enter the number of packages purchased. 7 | # The program should then display the amount of the discount (if any) 8 | # and the total amount of the purchase after the discount. 9 | 10 | def main(): 11 | 12 | number_purchased=int(input('Enter the number of packages purchased: ')) 13 | price=99 14 | 15 | if number_purchased>=10 and number_purchased<=19: 16 | discount=price*0.1 17 | elif number_purchased>=20 and number_purchased<=49: 18 | discount=price*0.2 19 | elif number_purchased>=50 and number_purchased<=99: 20 | discount=price*0.3 21 | else: 22 | discount=price*0.4 23 | 24 | total_amount=price*number_purchased-discount 25 | 26 | print('Discount % ',format(discount,'.2f'),sep='') 27 | print('Total amount after discount $',format(total_amount,'.2f'),sep='') 28 | 29 | main() 30 | -------------------------------------------------------------------------------- /Module3/Time_Calculator3_16.py: -------------------------------------------------------------------------------- 1 | # Time_Calculator3_16 2 | # Write a program that asks the user 3 | # to enter a number of seconds and works as follows: 4 | 5 | # There are 60 seconds in a minute. 6 | # If the number of seconds entered by the user is greater than or equal to 60, 7 | # the program should convert the number of seconds to minutes and seconds. 8 | 9 | # There are 3,600 seconds in an hour. 10 | # If the number of seconds entered by the user is greater 11 | # than or equal to 3,600, the program should convert the number of seconds to hours, minutes, and seconds . 12 | 13 | # There are 86,400 seconds in a day. 14 | # If the number of seconds entered by the user is greater than or equal to 86,400, 15 | # the program should convert the number of seconds to days, hours, minutes, and seconds. 16 | 17 | def main(): 18 | # ask user to enter a number of seconds. 19 | seconds=int(input('Enter a number of seconds: ')) 20 | 21 | # add 3 conditions if >= 60; if >=3600; if >=86.400 22 | # print the result 23 | 24 | if seconds>=60 and seconds<3600: 25 | minutes=seconds//60 26 | seconds=seconds%60 27 | print('It is',minutes,'minutes and',seconds,'seconds') 28 | elif seconds>=3600 and seconds<=86400: 29 | hours=seconds//3600 30 | minutes=hours%60 31 | seconds=seconds%60 32 | print('It is',hours,'hours,',minutes,'minutes and',seconds,'seconds') 33 | elif seconds>=86400: 34 | days=seconds//86400 35 | hours=days%3600 36 | minutes=hours%60 37 | seconds=seconds%60 38 | print('It is',days,'days',hours,'hours,',minutes,'minutes and',seconds,'seconds') 39 | 40 | main() 41 | -------------------------------------------------------------------------------- /Module3/Wi-Fi_Diagnostic_Tree3_17.py: -------------------------------------------------------------------------------- 1 | # Wi-Fi_Diagnostic_Tree3_17 2 | def main(): 3 | print('Reboot the computer and try to connect.') 4 | step1=str(input('Did that fix the problem? (Yes or No): ')) 5 | if step1=='Yes': 6 | print('You fixed a bad Wi-Fi connection!') 7 | if step1== 'No': 8 | print('Rebbot the router and try to connect.') 9 | 10 | step2=str(input('Did that fix the problem? (Yes or No): ')) 11 | if step2=='Yes': 12 | print('You fixed a bad Wi-Fi connection!') 13 | if step2== 'No': 14 | print('Make sure the cables beetween the router'\ 15 | ' & modem are plugged in firmly.') 16 | 17 | step3=str(input('Did that fix the problem? (Yes or No): ')) 18 | if step3=='Yes': 19 | print('You fixed a bad Wi-Fi connection!') 20 | if step3=='No': 21 | print('Move the router to a new location and try to connect.') 22 | 23 | step4=str(input('Did that fix the problem? (Yes or No): ')) 24 | if step4=='Yes': 25 | print('You fixed a bad Wi-Fi connection!') 26 | if step4== 'No': 27 | print('Get a new router.') 28 | 29 | 30 | main() 31 | 32 | -------------------------------------------------------------------------------- /Module4/Average Rainfall4_5.py: -------------------------------------------------------------------------------- 1 | # Average Rainfall4_5 2 | # Write a program that uses nested loops to collect data and calculate 3 | # the average rainfall over a period of years. 4 | # The program should first ask for the number of years. 5 | # The outer loop will iterate once for each year. 6 | # The inner loop will iterate twelve times, once for each month. 7 | # Each iteration of the inner loop will ask the user for 8 | # the inches of rainfall for that month. 9 | # After all iterations, the program should display the number of months, 10 | # the total inches of rainfall, and the average rainfall 11 | # per month for the entire period. 12 | 13 | 14 | def main(): 15 | 16 | total_month=0 17 | total_inch=0 18 | num_years=int(input('Enter the number of years: ')) 19 | for years in range (1,num_years+1): 20 | for month in range(1,13): 21 | rain_month=int(input('Enter the inches of ' +\ 22 | 'rainfall for that month '+format(month,'d')+\ 23 | ',year '+ format(years,'d')+': ')) 24 | total_inch+=rain_month 25 | total_month+=1 26 | average=total_inch/total_month 27 | print('Number of month: ',total_month) 28 | print('Total inches of rainfall: ',format(total_inch,'.2f')) 29 | print('Average rainfall per month for the entire period: ', format(average,'.2f')) 30 | 31 | 32 | 33 | main() 34 | -------------------------------------------------------------------------------- /Module4/Budget_Analysis4_3.py: -------------------------------------------------------------------------------- 1 | # Budget Analysis4_3 2 | # Write a program that asks the user to enter 3 | # the amount that he or she has budgeted for a month. 4 | # A loop should then prompt the user to enter 5 | # each of his or her expenses for the month and keep a running total. 6 | # When the loop finishes, the program should display the amount 7 | # that the user is over or under budget. 8 | 9 | 10 | def main(): 11 | 12 | total=0 13 | expenses=1 14 | budget=float(input('Enter your Budget for the month: ')) 15 | while expenses!=0: 16 | expenses=float(input('Enter your Expenses or "0" to quit: ')) 17 | total+=expenses 18 | left=budget-total 19 | print('Your Expenses for this month:',format(total,'.2f')) 20 | print('Money in the Budget :',format(left,'.2f')) 21 | 22 | 23 | main() 24 | -------------------------------------------------------------------------------- /Module4/Bug Collector4_1.py: -------------------------------------------------------------------------------- 1 | # Bug Collector4_1 2 | 3 | def main(): 4 | # Initialize the accumulator. 5 | total=0 6 | 7 | # Get the bugs collected for each day. 8 | for day in range(1,8): 9 | # Prompt the user to enter number of bugs 10 | print('Enter the number of bugs collected on day',day) 11 | bugs=int(input()) 12 | # Add bugs to total 13 | total+=bugs 14 | 15 | # Display the total bugs 16 | print('You collected a total of',total,'bugs') 17 | main() 18 | -------------------------------------------------------------------------------- /Module4/CalculatingFactorial4_12.py: -------------------------------------------------------------------------------- 1 | # Calculating the Factorial of a Number 2 | # In mathematics, the notation n! represents the factorial 3 | # of the nonnegative integer n. 4 | # The factorial of n is the product of all the nonnegative integers from 1 to n. 5 | # For example, 7!=1×2×3×4×5×6×7=5,040 and 4!=1×2×3×4=24 6 | # Write a program that lets the user 7 | # enter a nonnegative integer then uses a loop to calculate 8 | # the factorial of that number. Display the factorial. 9 | 10 | def main(): 11 | integer=0 12 | while integer<1: 13 | integer=int(input('Enter a nonnegative integer: ')) 14 | factorial=1 15 | 16 | for number in range(1,integer+1): 17 | factorial=factorial*number 18 | 19 | print('Factorial of',integer,'is',factorial) 20 | 21 | 22 | main() 23 | -------------------------------------------------------------------------------- /Module4/Calories_Burned4_2.py: -------------------------------------------------------------------------------- 1 | # Calories_Burned4_2 2 | 3 | # Running on a particular treadmill you burn 4.2 calories per minute. 4 | # Write a program that uses a loop to display the number of calories 5 | # burned after 10, 15, 20, 25, and 30 minutes. 6 | # Printe the table headings. 7 | # Print minutes and their calories. 8 | 9 | 10 | 11 | def main(): 12 | 13 | # Printe the table headings. 14 | print('Minutes\tCalories') 15 | print('-------','-------') 16 | 17 | # Print minutes and their calories. 18 | for num in [10,15,20,25]: 19 | per_minute=4.2*num 20 | print(num,'\t',format(per_minute,'.0f')) 21 | 22 | 23 | 24 | 25 | 26 | main() 27 | -------------------------------------------------------------------------------- /Module4/Celsius to Fahrenheit4_6.py: -------------------------------------------------------------------------------- 1 | # Celsius to Fahrenheit4_6 2 | # Write a program that displays a table 3 | # of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. 4 | # The formula for converting a temperature from Celsius to Fahrenheit 5 | # is F=95C+32 where F is the Fahrenheit temperature, 6 | # and C is the Celsius temperature. 7 | # Your program must use a loop to display the table. 8 | 9 | 10 | def main(): 11 | 12 | print('Celsius,C\tFahrenheit,F') 13 | print('---------\t------------') 14 | print() 15 | for C in range(0,21): 16 | F=(9/5)*C+32 17 | 18 | print(C,'\t',format(F,'12.0f')) 19 | 20 | 21 | main() 22 | -------------------------------------------------------------------------------- /Module4/Distance_Traveled4_4.py: -------------------------------------------------------------------------------- 1 | # Distance_Traveled4_4 2 | # The distance a vehicle travels can be calculated as follows: 3 | # distan⁡ce = speed × time 4 | # For example, if a train travels 40 miles per hour for three hours, 5 | # the distance traveled is 120 miles. 6 | # Write a program that asks the user for the speed of a vehicle 7 | # (in miles per hour) and the number of hours it has traveled. 8 | # It should then use a loop to display the distance 9 | # the vehicle has traveled for each hour of that time period. 10 | # Here is an example of the desired output: 11 | # What is the speed of the vehicle in mph? 40 12 | # How many hours has it traveled? 3 13 | # HourDistance Traveled 14 | # 1 40 15 | # 2 80 16 | # 3 120 17 | 18 | def main(): 19 | 20 | speed=int(input('What is the speed of the vehicle in mph?: ')) 21 | time=int(input('How many hours has it traveled?: ')) 22 | 23 | print('HoursDistance\tTraveled') 24 | 25 | for time in range(1,time+1): 26 | distance=speed*time 27 | print(time,'\t',distance) 28 | 29 | main() 30 | -------------------------------------------------------------------------------- /Module4/OceanLevel4_9.py: -------------------------------------------------------------------------------- 1 | # Tuition Increase4_10 2 | # At one college, the tuition for a full-time student is $8,000 per semester. 3 | # It has been announced that the tuition will increase 4 | # by 3 percent each year for the next 5 years. 5 | # Write a program with a loop that displays 6 | # the projected semester tuition amount for the next 5 years. 7 | 8 | 9 | def main(): 10 | tuition=8000 # tuition per semestr 11 | print('Num.Years\Tuition$') 12 | print('------------------') 13 | print() 14 | for years in [1,2,3,4,5]: 15 | tuition+=(3/100)*tuition 16 | print(years,'\t',format(tuition,'7.2f')) 17 | 18 | main() 19 | -------------------------------------------------------------------------------- /Module4/PenniesForPay4_7.py: -------------------------------------------------------------------------------- 1 | # Pennies for Pay4_7 2 | # Write a program that calculates the amount of money 3 | # a person would earn over a period of time if his or her salary is one penny 4 | # the first day, two pennies the second day, and continues to double each day. 5 | # The program should ask the user for the number of days. 6 | # Display a table showing what the salary was for each day, 7 | # then show the total pay at the end of the period. 8 | # The output should be displayed in a dollar amount, not the number of pennies. 9 | 10 | def main(): 11 | salary=0.01 12 | total=0 13 | num_days=int(input('Enter the number of days: ')) 14 | print('Day\tSalary') 15 | print('--------------') 16 | print() 17 | for days in range(num_days): 18 | salary=2**days 19 | print(days+1,'\t',salary) 20 | 21 | total+=salary 22 | total_dol=total*0.01 23 | print('Total pay $', total_dol) 24 | 25 | 26 | main() 27 | 28 | -------------------------------------------------------------------------------- /Module4/Population4_13.py: -------------------------------------------------------------------------------- 1 | # Population_4_13 2 | # Write a program that predicts the approximate size of a population of organisms. 3 | # The application should use text boxes to allow the user 4 | # to enter the starting number of organisms, 5 | # the average daily population increase (as a percentage), 6 | # and the number of days the organisms will be left to multiply. 7 | # For example, assume the user enters the following values: 8 | # Starting number of organisms: 2 9 | # Average daily increase: 30% 10 | # Number of days to multiply: 10 11 | # The program should display the following table of data: 12 | # Day ApproximatePopulation 13 | # 1 2 14 | # 2 2.6 15 | # 3 3.38 16 | # 4 4.394 17 | # 5 5.7122 18 | # 6 7.42586 19 | # 7 9.653619 20 | # 8 12.5497 21 | # 9 16.31462 22 | # 10 21.209 23 | 24 | def main(): 25 | population=int(input('Starting number of organisms: ')) 26 | average=float(input('Average daily increase: ')) 27 | num_days=int(input('Number of days to multiply: ')) 28 | average/= 100 29 | 30 | 31 | print('Day\tApproximate Population') 32 | print('---------------------------') 33 | for day in range(1,num_days+1): 34 | population=population+(average*population) 35 | print(day,'\t',population) 36 | 37 | 38 | 39 | main() 40 | -------------------------------------------------------------------------------- /Module4/Sum of Numbers4_8.py: -------------------------------------------------------------------------------- 1 | # Sum of Numbers4_8 2 | # Write a program with a loop that asks the user to enter 3 | # a series of positive numbers. 4 | # The user should enter a negative number to signal the end of the series. 5 | # After all the positive numbers have been entered, 6 | # the program should display their sum. 7 | 8 | 9 | def main(): 10 | total=0 11 | pos_num=0 12 | while pos_num>-1: 13 | total+=pos_num 14 | pos_num=float(input('Enter a positive numbers or negative to quit: ')) 15 | 16 | print('The sum all numbers is: ',total) 17 | 18 | 19 | main() 20 | -------------------------------------------------------------------------------- /Module4/Tuition_Increase4_10.py: -------------------------------------------------------------------------------- 1 | # Tuition Increase4_10 2 | # At one college, the tuition for a full-time student is $8,000 per semester. 3 | # It has been announced that the tuition will increase 4 | # by 3 percent each year for the next 5 years. 5 | # Write a program with a loop that displays 6 | # the projected semester tuition amount for the next 5 years. 7 | 8 | 9 | def main(): 10 | 11 | tuition=8000 12 | print('Num.Years\Tuition$') 13 | print('------------------') 14 | print() 15 | for years in [1,2,3,4,5]: 16 | tuition+=(3/100)*tuition 17 | print(years,'\t',format(tuition,'7.2f')) 18 | 19 | main() 20 | -------------------------------------------------------------------------------- /Module4/Weight_Loss4_11.py: -------------------------------------------------------------------------------- 1 | # Weight_Loss4_11 2 | # If a moderately active person cuts their calorie intake by 500 calories a day, 3 | # they can typically lose about 4 pounds a month. 4 | # Write a program that lets the user enter their starting weight, 5 | # then creates and displays a table showing what their expected weight will be 6 | # at the end of each month for 7 | # the next 6 months if they stay on this diet. 8 | 9 | 10 | def main(): 11 | 12 | 13 | weight=float(input('Enter your starting weight: ')) 14 | loss=4 15 | print('Month num\Weight') 16 | for month in range(6): 17 | weight-=loss 18 | print(month+1,'\t',weight) 19 | 20 | 21 | main() 22 | -------------------------------------------------------------------------------- /Module4/nested_loops4_14.py: -------------------------------------------------------------------------------- 1 | # nested_loops4_14 2 | # Write a program that uses nested loops to draw this pattern: 3 | # ******* 4 | # ****** 5 | # ***** 6 | # **** 7 | # *** 8 | # ** 9 | # * 10 | 11 | def main(): 12 | for row in range(7,0, -1): 13 | for colum in range(row, 0, -1): 14 | print('*',end='') 15 | print() 16 | 17 | main() 18 | -------------------------------------------------------------------------------- /Module5/Automobile_Costs5_4.py: -------------------------------------------------------------------------------- 1 | # Automobile_Costs5_4 2 | 3 | # Write a program that asks the user to enter 4 | # the monthly costs for the following expenses 5 | # incurred from operating his or her automobile: 6 | # loan payment, insurance, gas, oil, tires, and maintenance. 7 | # The program should then display the total monthly cost of these expenses, 8 | # and the total annual cost of these expenses. 9 | 10 | 11 | def main(): 12 | loan_payment=float(input('Enter loan payment: ')) 13 | insurance=float(input('Enter insurance: ')) 14 | gas=float(input('Enter gas expenses: ')) 15 | oil=float(input('Enter oil expenses: ')) 16 | tires=float(input('Enter tires expenses: ')) 17 | maintenance=float(input('Enter maintenance expenses: ')) 18 | 19 | monthly_cost=get_monthly_cost(loan_payment,insurance,gas,oil,tires,maintenance) 20 | print('Monthly cost is: $', monthly_cost) 21 | 22 | annual_cost=get_annual_cost(monthly_cost) 23 | print('Annual cost is: $', annual_cost) 24 | 25 | def get_monthly_cost(loan_payment,insurance,gas,oil,tires,maintenance): 26 | return loan_payment+insurance+gas+oil+tires+maintenance 27 | 28 | def get_annual_cost(monthly_cost): 29 | return monthly_cost*12 30 | 31 | main() 32 | -------------------------------------------------------------------------------- /Module5/Calories_Fat_Carbohydrates5_6.py: -------------------------------------------------------------------------------- 1 | #Calories_Fat_Carbohydrates5_6 2 | 3 | # A nutritionist who works for a fitness club helps members 4 | # by evaluating their diets. 5 | # As part of her evaluation, she asks members 6 | # for the number of fat grams and carbohydrate grams that they consumed in a day. 7 | 8 | # Then, she calculates the number of calories that result from the fat, 9 | # using the following formula: 10 | # calories from fat=fat grams×9 11 | 12 | # Next, she calculates the number of calories that result from the carbohydrates, 13 | # using the following formula: 14 | # calories from carbs=carb grams × 4 15 | # The nutritionist asks you to write a program that will make these calculations. 16 | 17 | 18 | def main(): 19 | number_fat=float(input('Enter number of fat grams that consumed in a day: ')) 20 | number_carb=float(input('Enter number of carbohydrate grams'+ 21 | 'that consumed in a day: ')) 22 | 23 | calories_fat=get_calories_fat(number_fat) 24 | calories_carbs=get_calories_carbs(number_carb) 25 | 26 | print('The number of calories that result from the fat: ',calories_fat) 27 | print('The number of calories that result from the carbohydrates: ', calories_carbs) 28 | 29 | 30 | def get_calories_fat(fat): 31 | return fat*9 32 | 33 | def get_calories_carbs(carb): 34 | return carb*4 35 | 36 | 37 | main() 38 | -------------------------------------------------------------------------------- /Module5/Falling_Distance5_13.py: -------------------------------------------------------------------------------- 1 | # Falling_Distance5_13 2 | 3 | # When an object is falling because of gravity, 4 | # the following formula can be used to determine the distance 5 | # the object falls in a specific time period: d=12gt2 6 | 7 | # The variables in the formula are as follows: 8 | # d is the distance in meters, 9 | # g is 9.8, 10 | # and t is the amount of time, in seconds, that the object has been falling. 11 | 12 | # Write a function named falling_distance that accepts 13 | # an object’s falling time (in seconds) as an argument. 14 | 15 | # The function should return the distance, in meters, 16 | # that the object has fallen during that time interval. 17 | 18 | # Write a program that calls the function in a loop 19 | # that passes the values 1 through 10 as arguments 20 | # and displays the return value. 21 | 22 | 23 | g=9.8 24 | def main(): 25 | 26 | for falling_time in range (1,10): 27 | falling_distance=get_falling_distance(falling_time) 28 | print('Time\tDistance') 29 | print(falling_time,'\t',format(falling_distance,'.1f')) 30 | print() 31 | 32 | def get_falling_distance(falling_time): 33 | return 1/2*g*(falling_time**2) 34 | 35 | main() 36 | -------------------------------------------------------------------------------- /Module5/Feet_to_Inches5_10.py: -------------------------------------------------------------------------------- 1 | # Feet_to_Inches5_10 2 | 3 | # The Feet to Inches Problem One foot equals 12 inches. 4 | # Write a function named feet_to_inches that accepts a number of feet 5 | # as an argument and returns the number of inches in that many feet. 6 | # Use the function in a program that prompts the user 7 | # to enter a number of feet then displays 8 | # the number of inches in that many feet. 9 | 10 | # COnstant for the number of inches per foot. 11 | INCHES_PER_FOOT=12 12 | 13 | def main(): 14 | # Get a number of feet from the user. 15 | feet=int(input('Enter a number of feet: ')) 16 | 17 | # Convert that to inches. 18 | print(feet,'equals',feet_to_inches(feet),'inches.') 19 | 20 | # The fee_to_inches function converts feet to inches. 21 | def feet_to_inches(feet): 22 | return feet*INCHES_PER_FOOT 23 | 24 | # Call the main function. 25 | main() 26 | 27 | -------------------------------------------------------------------------------- /Module5/FutureValue5_19.py: -------------------------------------------------------------------------------- 1 | # FutureValue5_19 2 | #F=P(1+i)t 3 | #The terms in the formula are: 4 | #F is the future value of the account after the specified time period. 5 | #P is the present value of the account. 6 | #i is the monthly interest rate. 7 | #t is the number of months. 8 | 9 | #Write a program that prompts the user to enter the account’s present value, 10 | #monthly interest rate, and the number of months that the money will be left 11 | #in the account. The program should pass these values to a function 12 | #that returns the future value of the account, 13 | #after the specified number of months. 14 | #The program should display the account’s future value 15 | 16 | 17 | def main(): 18 | p=float(input('Account’s present value:$')) 19 | i=float(input('Monthly interest rate:%')) 20 | t=float(input('The number of months that the money will be left'+ 21 | 'in the account: ')) 22 | f=future_value(p,i,t) 23 | print('Future value is $',format(f,'.2f'),sep='') 24 | 25 | def future_value(p,i,t): 26 | f=p*(1+i)**t 27 | return f 28 | 29 | 30 | main() 31 | 32 | -------------------------------------------------------------------------------- /Module5/Insurance5_3.py: -------------------------------------------------------------------------------- 1 | # Insurance5_3 2 | 3 | # Many financial experts advise that property owners should 4 | # insure their homes or buildings for at least 80 percent of the amount 5 | # it would cost to replace the structure. 6 | # Write a program that asks the user to enter the replacement cost 7 | # of a building, then displays the minimum 8 | # amount of insurance he or she should buy for the property. 9 | 10 | 11 | def main(): 12 | cost_replacement=float(input('Enter the replacement cost of a building: ')) 13 | 14 | amount_insurance=get_amount_insurance(cost_replacement) 15 | print('Amount of insurance you should buy for the property: $', 16 | amount_insurance) 17 | 18 | def get_amount_insurance(cost): 19 | return cost*0.8 20 | 21 | 22 | main() 23 | -------------------------------------------------------------------------------- /Module5/Kilometer_Converte5_1.py: -------------------------------------------------------------------------------- 1 | # This program converts kilometers to miles. 2 | CONVERSION_FACTOR=0.6214 3 | 4 | 5 | # The main function gets a distance in kilometers and calls 6 | # the show_miles function to convert it. 7 | def main(): 8 | # Get the distance in kilometers. 9 | kilometers=float(input('Enter a distance in kilometers: ')) 10 | 11 | # Display the distance converted to miles. 12 | show_miles(kilometers) 13 | 14 | # The show_miles function converts the parameter km from 15 | # kilometers to miles and displays the result. 16 | 17 | def show_miles(km): 18 | # Calculate miles: 19 | miles=km*CONVERSION_FACTOR 20 | 21 | 22 | # Display the miles. 23 | print(km,'kilometers equals',format(miles,'.2f'),'miles.') 24 | 25 | 26 | # Call the main function. 27 | main() 28 | 29 | -------------------------------------------------------------------------------- /Module5/Kinetic_Energy5_14.py: -------------------------------------------------------------------------------- 1 | # Kinetic_Energy5_14 2 | # In physics, an object that is in motion is said to have kinetic energy. 3 | # The following formula can be used to determine a moving object’s 4 | # kinetic energy: KE=1\2*m(v**2) 5 | # The variables in the formula are as follows: 6 | # KE is the kinetic energy, m is the object’s mass in kilograms, 7 | # and v is the object’s velocity in meters per second. 8 | # Write a function named kinetic_energy that accepts an object’s mass 9 | # (in kilograms) and velocity (in meters per second) as arguments. 10 | # The function should return the amount of kinetic energy that the object has. 11 | 12 | # Write a program that asks the user to enter values for mass and velocity, 13 | # then calls the kinetic_energy function to get the object’s kinetic energy. 14 | 15 | def main(): 16 | mass=float(input('Enter values for mass in kilograms: ')) 17 | velocity=float(input('Enter values for velocity in meters per second: ')) 18 | 19 | kinetic_energy=get_kinetic_energy(mass,velocity) 20 | print('Kinetic energy is',format(kinetic_energy,'.2f')) 21 | 22 | def get_kinetic_energy(mass,velocity): 23 | return 1/2*mass*velocity**2 24 | 25 | main() 26 | -------------------------------------------------------------------------------- /Module5/Math_Quiz5_11.py: -------------------------------------------------------------------------------- 1 | # Math_Quiz5_11 2 | 3 | # Write a program that gives simple math quizzes. 4 | # The program should display two random numbers that are to be added, 5 | # such as: 247 + 129 6 | # The program should allow the student to enter the answer. 7 | # If the answer is correct, a message of congratulations should be displayed. 8 | # If the answer is incorrect, 9 | # a message showing the correct answer should be displayed. 10 | 11 | 12 | import random 13 | MIN=1 14 | MAX=1000 15 | 16 | def main(): 17 | keep_going='y' 18 | while keep_going=='y' or keep_going=='Y': 19 | 20 | number1=random.randint(MIN,MAX) 21 | number2=random.randint(MIN,MAX) 22 | print(number1,'+',number2) 23 | answer=int(input('Enter the answer: ')) 24 | 25 | if answer == math_quiz(number1,number2): 26 | print('Congratulations! The answer',answer,'is correct!') 27 | else: 28 | print('Nope! The answer is',math_quiz(number1,number2)) 29 | 30 | keep_going=input('Try again (y=yes):') 31 | 32 | def math_quiz(number1,number2): 33 | return number1+number2 34 | 35 | main() 36 | -------------------------------------------------------------------------------- /Module5/Maximum_of_Two_Values5_12.py: -------------------------------------------------------------------------------- 1 | # Maximum_of_Two_Values5_12 2 | 3 | # Write a function named max that accepts two integer values as arguments 4 | # and returns the value that is the greater of the two. 5 | # For example, if 7 and 12 are passed as arguments to the function, 6 | # the function should return 12. 7 | # Use the function in a program that prompts the user to enter two integer values. 8 | # The program should display the value that is the greater of the two. 9 | 10 | 11 | def main(): 12 | number1=int(input('Enter the number1: ')) 13 | number2=int(input('Enter the number2: ')) 14 | max(number1,number2) 15 | print('The max number is', max(number1,number2)) 16 | 17 | 18 | def max(number1,number2): 19 | if number1>number2: 20 | return number1 21 | else: 22 | return number2 23 | 24 | main() 25 | -------------------------------------------------------------------------------- /Module5/Monthly_Sales_Tax5_9.py: -------------------------------------------------------------------------------- 1 | # Monthly_Sales_Tax5_9 2 | 3 | # A retail company must file a monthly sales tax report 4 | # listing the total sales for the month, and the amount of state 5 | # and county sales tax collected. The state sales tax rate is 5 percent 6 | # and the county sales tax rate is 2.5 percent. 7 | # Write a program that asks the user to enter the total sales for the month. 8 | # From this figure, the application should calculate and display the following: 9 | # The amount of county sales tax 10 | # The amount of state sales tax 11 | # The total sales tax (county plus state) 12 | 13 | 14 | rate_state_tax=0.05 15 | rate_county_tax=0.025 16 | 17 | def main(): 18 | total_sales=float(input('Enter the total sales for the month: $ ')) 19 | county_tax=get_county_tax(total_sales) 20 | sales_tax=get_sales_tax(total_sales) 21 | total_tax=get_total_tax(county_tax,sales_tax) 22 | 23 | print('The amount of county sales tax: $',format(county_tax,'.2f'),sep='') 24 | print('The amount of state sales tax: $',format(sales_tax,'.2f'),sep='' ) 25 | print('The total sales tax (county plus state: $',format(total_tax,'.2f'),sep='') 26 | 27 | def get_county_tax(sales): 28 | return sales*rate_county_tax 29 | def get_sales_tax(sales): 30 | return sales*rate_state_tax 31 | def get_total_tax(county,sales): 32 | return county+sales 33 | 34 | main() 35 | -------------------------------------------------------------------------------- /Module5/Odd_Even Counter5_16.py: -------------------------------------------------------------------------------- 1 | #Odd_Even Counter5_16 2 | # In this chapter, you saw an example of how to write an algorithm that determines 3 | # whether a number is even or odd. Write a program that generates 100 random numbers 4 | # and keeps a count of how many of those random numbers are even, 5 | # and how many of them are odd. 6 | 7 | import random 8 | def main(): 9 | even_number=0 10 | odd_number=0 11 | 12 | for i in range (1,101): 13 | number=random.randint(0,101) 14 | print(number,end=' ') 15 | if(even_odd_count(number)== True): 16 | even_number+=1 17 | else: 18 | odd_number+=1 19 | print() 20 | print(even_number,'numbers are even and', odd_number,'numbers are odd!') 21 | 22 | 23 | def even_odd_count(number): 24 | return number%2==0 25 | 26 | 27 | 28 | 29 | 30 | 31 | main() 32 | -------------------------------------------------------------------------------- /Module5/Paint_Job_Estimator5_8.py: -------------------------------------------------------------------------------- 1 | # Paint_Job_Estimator5_8 2 | 3 | # A painting company has determined 4 | # that for every 112 square feet of wall space, 5 | # one gallon of paint and eight hours of labor will be required. 6 | # The company charges $35.00 per hour for labor. 7 | # Write a program that asks the user to enter 8 | # the square feet of wall space to be painted and the price of the paint per gallon. 9 | # The program should display the following data: 10 | # The number of gallons of paint required 11 | # The hours of labor required 12 | # The cost of the paint 13 | # The labor charges 14 | # The total cost of the paint job 15 | 16 | def main(): 17 | wall_space=float(input('Enter the square feet of wall space: ')) 18 | price_paint=float(input('Enter the price of the paint per gallon: ')) 19 | 20 | number_paint=get_number_paint(wall_space) 21 | hours_labor=get_hours_labor(wall_space) 22 | cost_paint=get_cost_paint(number_paint,price_paint) 23 | labor_charges=get_labor_charges(hours_labor) 24 | total_cost=get_total_cost(cost_paint,labor_charges) 25 | 26 | print('The number of gallons of paint required: ', format(number_paint,'.2f')) 27 | print('The hours of labor required: ', format(hours_labor,'.2f')) 28 | print('The cost of the paint: $', format(cost_paint,'.2f'),sep='') 29 | print('The labor charges: $',format(labor_charges,'.2f'),sep='') 30 | print('The total cost of the paint job: $',format(total_cost,'.2f'),sep='') 31 | 32 | def get_number_paint(space): 33 | return space/112 34 | def get_hours_labor(space): 35 | return space/112*8 36 | def get_cost_paint(number_paint,price_paint): 37 | return number_paint*price_paint 38 | def get_labor_charges(hours): 39 | return hours*35 40 | def get_total_cost(paint,labor): 41 | return paint+labor 42 | 43 | main() 44 | -------------------------------------------------------------------------------- /Module5/Prime_Number_List5-18.py: -------------------------------------------------------------------------------- 1 | # Prime_Number_List5-18 2 | # This exercise assumes that you have already written the is_prime function 3 | # in Programming Exercise 17. 4 | # Write another program that displays all of the prime numbers from 1 to 100. 5 | # The program should have a loop that calls the is_prime function. 6 | 7 | 8 | def is_prime(number): 9 | even =0 10 | if number<=1: 11 | return False 12 | for currentNumber in range(1,number+1): 13 | if number%currentNumber==0: 14 | even=even+1 15 | if even>2: 16 | return False 17 | return True 18 | def main(): 19 | for number in range (1,101): 20 | if is_prime(number): 21 | print(number,end=' ') 22 | 23 | 24 | 25 | 26 | main() 27 | -------------------------------------------------------------------------------- /Module5/Prime_Numbers5_17.py: -------------------------------------------------------------------------------- 1 | # Prime_Numbers5_17 2 | # A prime number is a number that is only evenly divisible by itself and 1. 3 | # For example, the number 5 is prime because it can only be evenly 4 | # divided by 1 and 5. 5 | # The number 6, however, is not prime because it can be divided 6 | # evenly by 1, 2, 3, and 6. 7 | 8 | # Write a Boolean function named is_prime 9 | # which takes an integer as an argument and returns true 10 | # if the argument is a prime number, or false otherwise. 11 | 12 | # Use the function in a program that prompts the user to enter a number 13 | # then displays a message indicating whether the number is prime. 14 | 15 | # Tip: 16 | # Recall that the % operator divides one number by another 17 | # and returns the remainder of the division. 18 | # In an expression such as num1 % num2, 19 | # the % operator will return 0 if num1 is evenly divisible by num2. 20 | 21 | def isPrime(number): 22 | even =0 23 | if number<=1: 24 | return False 25 | for currentNumber in range(1,number+1): 26 | if number%currentNumber==0: 27 | even=even+1 28 | if even>2: 29 | return False 30 | return True 31 | def main(): 32 | userNumber=int(input('Enter the number: ')) 33 | if isPrime(userNumber): 34 | print(userNumber,'is a prime number') 35 | else: 36 | print(userNumber,'is NOT a prime number') 37 | 38 | 39 | 40 | main() 41 | -------------------------------------------------------------------------------- /Module5/Property_tax5_5.py: -------------------------------------------------------------------------------- 1 | # Property_Tax5_5 2 | 3 | # A county collects property taxes on the assessment value of property, 4 | # which is 60 percent of the property’s actual value. 5 | # For example, if an acre of land is valued at $10,000, 6 | # its assessment value is $6,000. 7 | # The property tax is then 72¢ for each $100 of the assessment value. 8 | # The tax for the acre assessed at $6,000 will be $43.20. 9 | # Write a program that asks for the actual value of a piece 10 | # of property and displays the assessment value and property tax. 11 | 12 | 13 | def main(): 14 | 15 | actual_value=float(input('Actual value of a piece of property: ')) 16 | assesment_value=get_assesment_value(actual_value) 17 | property_tax=get_property_tax(assesment_value) 18 | print('The assessment value: $',assesment_value) 19 | print('Property tax: $',format(property_tax,'.2f')) 20 | 21 | 22 | def get_assesment_value(value): 23 | return value*0.6 24 | 25 | def get_property_tax(value): 26 | return value/100*0.72 27 | 28 | 29 | main() 30 | -------------------------------------------------------------------------------- /Module5/Random_number5_20.py: -------------------------------------------------------------------------------- 1 | # Random_number5_20 2 | 3 | # Write a program that generates a random number in the range of 1 through 100, 4 | # and asks the user to guess what the number is. 5 | # If the user’s guess is higher than the random number, 6 | # the program should display “Too high, try again.” 7 | # If the user’s guess is lower than the random number, 8 | # the program should display “Too low, try again.” 9 | # If the user guesses the number, the application should congratulate 10 | # the user and generate a new random number so the game can start over. 11 | 12 | import random 13 | def main(): 14 | 15 | user_number=int 16 | while user_number!='': 17 | number=random.randrange(1,100) 18 | user_number=int(input('Enter the number ')) 19 | 20 | if number>=user_number: 21 | print('Too low,try again,the number was',number) 22 | elif number<=user_number: 23 | print('Too high, try again,the number was',number) 24 | elif number==number_user: 25 | print('Congratulations! The number was',number) 26 | 27 | main() 28 | -------------------------------------------------------------------------------- /Module5/Rock,Paper,Scissors5_21.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def generateRandomNuber(): 4 | randomNumber=random.randint(1,3) 5 | return randomNumber 6 | 7 | def getCompChoice(randomNumber): 8 | if randomNumber==1: 9 | compChoice='rock' 10 | elif randomNumber==2: 11 | compChoice='paper' 12 | elif randomNumber==3: 13 | compChoice='scissors' 14 | return compChoice 15 | 16 | def getUserChoice(): 17 | userChoice=input('Enter your choice: rock, paper or scissors: ') 18 | if userChoice=='' or userChoice=='rock' or userChoice=='paper' or userChoice=='scissors': 19 | return userChoice 20 | print('Error!You have to choose: rock,paper or scissors! ') 21 | return getUserChoice() 22 | 23 | def winnerIs(compChoice,userChoice): 24 | rockMessage='The rock smashes the scissors.' 25 | scissorsMessage='Scissors cuts paper.' 26 | paperMessage='Paper wraps rock.' 27 | winner='no winner' 28 | message='' 29 | 30 | if compChoice=='rock': 31 | if userChoice=='scissors': 32 | winner='Computer' 33 | message=rockMessage 34 | elif userChoice=='paper': 35 | winner='You' 36 | message=paperMessage 37 | 38 | elif compChoice=='scissors': 39 | if userChoice=='paper': 40 | winner='Computer' 41 | message=scissorsMessage 42 | elif userChoice=='rock': 43 | winner='You' 44 | message=rockMessage 45 | 46 | else: 47 | if userChoice=='rock': 48 | winner='Computer' 49 | message=paperMessage 50 | elif userChoice=='scissors': 51 | winner='You' 52 | message=scissorsMessage 53 | 54 | return winner, message 55 | 56 | def start(compWins, userWins): 57 | randomNumber=generateRandomNuber() 58 | compChoice=getCompChoice(randomNumber) 59 | userChoice=getUserChoice() 60 | if userChoice=='': 61 | return 62 | print('The computer chose',compChoice) 63 | winner,message=winnerIs(compChoice,userChoice) 64 | 65 | if winner!='no winner': 66 | print(winner,'won(',message,')') 67 | if winner=='Computer': 68 | compWins+=1 69 | else: 70 | userWins+=1 71 | else: 72 | print('You both have the same choice') 73 | 74 | print('Score (Computer : User) ',compWins,':',userWins,'\n') 75 | 76 | start(compWins, userWins) 77 | 78 | 79 | def main(): 80 | compWins=0 81 | userWins=0 82 | 83 | start(compWins,userWins) 84 | 85 | main() 86 | -------------------------------------------------------------------------------- /Module5/Sales_Tax_Program_Refactoring5_2.py: -------------------------------------------------------------------------------- 1 | # Sales_Tax_Program_Refactoring5_2 2 | 3 | rate_state_tax=0.05 4 | rate_county_tax=0.025 5 | 6 | def main(): 7 | # ask user to enter the amount of purchase 8 | amount_purchase=float(input('Enter the amount of purchase: $')) 9 | 10 | # calculate 1.state_tax, 2.county_tax, 3.total_salesTax, 4.total_sale 11 | state_tax=get_state_tax(amount_purchase) 12 | county_tax=get_county_tax(amount_purchase) 13 | total_tax=get_total_tax(state_tax,county_tax) 14 | total_sales=get_total_sales(amount_purchase,total_tax) 15 | 16 | # display result 17 | print('State Tax: $',format(state_tax,',.2f'),sep='') 18 | print('County Tax: $',format(county_tax,',.2f'),sep='') 19 | print('Tatal Sales Tax: $',format(total_tax,',.2f'),sep='') 20 | print('Total of the sale: $',format(total_sales,',.2f'),sep='') 21 | 22 | 23 | def get_state_tax(amount_purchase): 24 | return amount_purchase*rate_state_tax 25 | 26 | def get_county_tax(amount_purchase): 27 | return amount_purchase*rate_county_tax 28 | 29 | def get_total_tax(state_tax, county_tax): 30 | return state_tax+county_tax 31 | 32 | def get_total_sales(amount,tax): 33 | return amount+tax 34 | 35 | main() 36 | -------------------------------------------------------------------------------- /Module5/Stadium_Seating5_7.py: -------------------------------------------------------------------------------- 1 | # Stadium_Seating5_7 2 | # There are three seating categories at a stadium. 3 | # Class A seats cost $20, 4 | # Class B seats cost $15, 5 | # and Class C seats cost $10. 6 | # Write a program that asks how many tickets for each class of seats were sold, 7 | # then displays the amount of income generated from ticket sales. 8 | 9 | a=20 10 | b=15 11 | c=10 12 | 13 | def main(): 14 | 15 | sold_a=int(input('Enter how many tickets class A were sold: ')) 16 | sold_b=int(input('Enter how many tickets class B were sold: ')) 17 | sold_c=int(input('Enter how many tickets class C were sold: ')) 18 | 19 | 20 | total_sold=get_total_sold(sold_a,sold_b,sold_c) 21 | print('The amount of income generated from tickets sales: $',total_sold) 22 | 23 | 24 | def get_total_sold(sold_a,sold_b,sold_c): 25 | return sold_a*a+sold_b*b+sold_c*c 26 | 27 | 28 | 29 | main() 30 | -------------------------------------------------------------------------------- /Module5/Test_Average_and_Grade5_15.py: -------------------------------------------------------------------------------- 1 | # Test_Average_and_Grade5_15 2 | 3 | # Write a program that asks the user to enter five test scores. 4 | # The program should display a letter grade for each score 5 | # and the average test score. 6 | # Write the following functions in the program: calc_average. 7 | # This function should accept five test scores as arguments and return the 8 | # average of the scores. 9 | 10 | # determine_grade. 11 | # This function should accept a test score as an argument 12 | #and return a letter grade for the score based on the following grading scale: 13 | # Score Letter Grade 14 | #90–100 A / 80–89 B/ 70–79 C / 60–69 D / Below 60F 15 | 16 | number=5 17 | 18 | def main(): 19 | total=0 20 | for i in range(1,number+1): 21 | test=int(input('Enter the test score '+format(i,'d')+':')) 22 | 23 | grade=determine_grade(test) 24 | print('Grade is ',grade) 25 | total+=test 26 | 27 | 28 | average=calc_average(total) 29 | print('Average score is :',average,'%','and grade is',determine_grade(average)) 30 | 31 | def calc_average(test): 32 | return test/number 33 | 34 | def determine_grade(test): 35 | if test >90 and test<=100: 36 | return 'A' 37 | elif test>80 and test<=90: 38 | return 'B' 39 | elif test>70 and test<=79: 40 | return 'C' 41 | elif test>60 and test<=69: 42 | return 'D' 43 | else: 44 | return 'F' 45 | 46 | main() 47 | -------------------------------------------------------------------------------- /Module7/8_ball_responses.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanaPanchyshena/Python-solutions-programming-exercises/011f1872d0d967cb85cdf1fdb8d6a460c4fabdd1/Module7/8_ball_responses.txt -------------------------------------------------------------------------------- /Module7/BoyNames.txt: -------------------------------------------------------------------------------- 1 | Liam 2 | Noah 3 | William 4 | James 5 | Logan 6 | Benjamin 7 | Mason 8 | Elijah 9 | Oliver 10 | Jacob 11 | Lucas 12 | Michael 13 | Alexander 14 | Ethan 15 | Daniel 16 | Matthew 17 | Aiden 18 | Henry 19 | Joseph 20 | Jackson 21 | Samuel 22 | Sebastian 23 | David 24 | Carter 25 | Wyatt 26 | Jayden 27 | John 28 | Owen 29 | Dylan 30 | Luke 31 | Gabriel 32 | Anthony 33 | Isaac 34 | Grayson 35 | Jack 36 | Julian 37 | Levi 38 | Christopher 39 | Joshua 40 | Andrew 41 | Lincoln 42 | Mateo 43 | Ryan 44 | Jaxon 45 | Nathan 46 | Aaron 47 | Isaiah 48 | Thomas 49 | Charles 50 | Caleb 51 | Josiah 52 | Christian 53 | Hunter 54 | Eli 55 | Jonathan 56 | Connor 57 | Landon 58 | Adrian 59 | Asher 60 | Cameron 61 | Leo 62 | Theodore 63 | Jeremiah 64 | Hudson 65 | Robert 66 | Easton 67 | Nolan 68 | Nicholas 69 | Ezra 70 | Colton 71 | Angel 72 | Brayden 73 | Jordan 74 | Dominic 75 | Austin 76 | Ian 77 | Adam 78 | Elias 79 | Jaxson 80 | Greyson 81 | Jose 82 | Ezekiel 83 | Carson 84 | Evan 85 | Maverick 86 | Bryson 87 | Jace 88 | Cooper 89 | Xavier 90 | Parker 91 | Roman 92 | Jason 93 | Santiago 94 | Chase 95 | Sawyer 96 | Gavin 97 | Leonardo 98 | Kayden 99 | Ayden 100 | Jameson 101 | Kevin 102 | Bentley 103 | Zachary 104 | Everett 105 | Axel 106 | Tyler 107 | Micah 108 | Vincent 109 | Weston 110 | Miles 111 | Wesley 112 | Nathaniel 113 | Harrison 114 | Brandon 115 | Cole 116 | Declan 117 | Luis 118 | Braxton 119 | Damian 120 | Silas 121 | Tristan 122 | Ryder 123 | Bennett 124 | George 125 | Emmett 126 | Justin 127 | Kai 128 | Max 129 | Diego 130 | Luca 131 | Ryker 132 | Carlos 133 | Maxwell 134 | Kingston 135 | Ivan 136 | Maddox 137 | Juan 138 | Ashton 139 | Jayce 140 | Rowan 141 | Kaiden 142 | Giovanni 143 | Eric 144 | Jesus 145 | Calvin 146 | Abel 147 | King 148 | Camden 149 | Amir 150 | Blake 151 | Alex 152 | Brody 153 | Malachi 154 | Emmanuel 155 | Jonah 156 | Beau 157 | Jude 158 | Antonio 159 | Alan 160 | Elliott 161 | Elliot 162 | Waylon 163 | Xander 164 | Timothy 165 | Victor 166 | Bryce 167 | Finn 168 | Brantley 169 | Edward 170 | Abraham 171 | Patrick 172 | Grant 173 | Karter 174 | Hayden 175 | Richard 176 | Miguel 177 | Joel 178 | Gael 179 | Tucker 180 | Rhett 181 | Avery 182 | Steven 183 | Graham 184 | Kaleb 185 | Jasper 186 | Jesse 187 | Matteo 188 | Dean 189 | Zayden 190 | Preston 191 | August 192 | Oscar 193 | Jeremy 194 | Alejandro 195 | Marcus 196 | Dawson 197 | Lorenzo 198 | Messiah 199 | Zion 200 | Maximus -------------------------------------------------------------------------------- /Module7/Charge_Account_Validation7_5.py: -------------------------------------------------------------------------------- 1 | #Charge_Account_Validation7_5 2 | # If you have downloaded the source code from 3 | # charge_accounts.txt has a list of a company’s 4 | # valid charge account numbers. Each account number is a seven-digit number, 5 | # such as 5658845. 6 | # Write a program that reads the contents of the file into a list. 7 | # The program should then ask the user to enter a charge account number. 8 | # The program should determine whether the number 9 | # is valid by searching for it in the list. If the number 10 | # is in the list, the program should display a message indicating 11 | # the number is valid. If the number is not in the list, 12 | # the program should display a message indicating the number is invalid. 13 | 14 | def get_content(source): 15 | if source=='file': 16 | return read_file('charge_accounts.txt') 17 | elif source=='server': 18 | return read_server() 19 | 20 | def read_file(file_name): 21 | new_file=open(file_name,'r') 22 | list_charge=new_file.readlines() 23 | new_file.close() 24 | return list_charge 25 | 26 | def proccess_content(content): 27 | for index in range(0,len(content)): 28 | content[index]=content[index].rstrip('\n') 29 | return content 30 | 31 | def get_input(): 32 | return input('Enter a charge account number: ') 33 | 34 | def check_account(search,list_charge): 35 | return search in list_charge 36 | 37 | def print_results(search,result): 38 | if result: 39 | print(search,'number is valid') 40 | else: 41 | print(search,'number is not in the list') 42 | 43 | 44 | def main(): 45 | content=get_content('file') 46 | account_list=proccess_content(content) 47 | account=get_input() 48 | result=check_account(account,account_list) 49 | print_results(account,result) 50 | 51 | main() 52 | -------------------------------------------------------------------------------- /Module7/Driver’s_License_Exam7-7.py: -------------------------------------------------------------------------------- 1 | # Driver’s_License_Exam7-7 2 | # The local driver’s license office has asked you to create an application 3 | # that grades the written portion of the driver’s license exam. 4 | # The exam has 20 multiple-choice questions. 5 | # Here are the correct answers: 6 | # 1. A 2. C 3. A 4. A 5. D 6. B 7. C 8. A 9. C 10. B 7 | # 11. A 12. D 13. C 14.A 15.D 16. C 17. B 18. B 19. D 20. A 8 | # Your program should store these correct answers in a list. 9 | # The program should read the student’s answers for each of the 20 questions 10 | # from a text file and store the answers in another list. 11 | # (Create your own text file to test the application.) 12 | # After the student’s answers have been read from the file, 13 | # the program should display a message indicating 14 | # whether the student passed or failed the exam. 15 | # (A student must correctly answer 15 of the 20 questions to pass the exam.) 16 | # It should then display the total number of correctly answered questions, 17 | # the total number of incorrectly answered questions, and a list showing 18 | # the question numbers of the incorrectly answered questions. 19 | 20 | 21 | 22 | def correct_answers(): 23 | list_answers=['A','C','A','A','D','B','C','A','C','B', 24 | 'A','D','C','A','D','C','B','B','D','A'] 25 | return list_answers 26 | 27 | def get_answers(): 28 | user_list=[] 29 | read_file=open('user_answers.txt','r') 30 | for i in read_file: 31 | i=i.rstrip('\n') 32 | user_list.append(i) 33 | return user_list 34 | 35 | def check_answers(list_answers,user_list): 36 | count=0 37 | print('Correct answers',list_answers) 38 | print('Your answers',user_list) 39 | wrong_answers=[] 40 | for i in range(20): 41 | if list_answers[i]==user_list[i]: 42 | count+=1 43 | else: 44 | wrong_answers.append(i) 45 | if count<15: 46 | print('You failed') 47 | else: 48 | print('You passed') 49 | print('The number of correctly answerd question is', count) 50 | print('The number of incorrectly answerd question is', 20 - count) 51 | print('The question numbers of the incorrectly answered quesions are', 52 | wrong_answers) 53 | 54 | def main(): 55 | list_answers=correct_answers() 56 | user_list=get_answers() 57 | check_answers(list_answers,user_list) 58 | main() 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Module7/GirlNames.txt: -------------------------------------------------------------------------------- 1 | Emma 2 | Olivia 3 | Ava 4 | Isabella 5 | Sophia 6 | Mia 7 | Charlotte 8 | Amelia 9 | Evelyn 10 | Abigail 11 | Harper 12 | Emily 13 | Elizabeth 14 | Avery 15 | Sofia 16 | Ella 17 | Madison 18 | Scarlett 19 | Victoria 20 | Aria 21 | Grace 22 | Chloe 23 | Camila 24 | Penelope 25 | Riley 26 | Layla 27 | Lillian 28 | Nora 29 | Zoey 30 | Mila 31 | Aubrey 32 | Hannah 33 | Lily 34 | Addison 35 | Eleanor 36 | Natalie 37 | Luna 38 | Savannah 39 | Brooklyn 40 | Leah 41 | Zoe 42 | Stella 43 | Hazel 44 | Ellie 45 | Paisley 46 | Audrey 47 | Skylar 48 | Violet 49 | Claire 50 | Bella 51 | Aurora 52 | Lucy 53 | Anna 54 | Samantha 55 | Caroline 56 | Genesis 57 | Aaliyah 58 | Kennedy 59 | Kinsley 60 | Allison 61 | Maya 62 | Sarah 63 | Madelyn 64 | Adeline 65 | Alexa 66 | Ariana 67 | Elena 68 | Gabriella 69 | Naomi 70 | Alice 71 | Sadie 72 | Hailey 73 | Eva 74 | Emilia 75 | Autumn 76 | Quinn 77 | Nevaeh 78 | Piper 79 | Ruby 80 | Serenity 81 | Willow 82 | Everly 83 | Cora 84 | Kaylee 85 | Lydia 86 | Aubree 87 | Arianna 88 | Eliana 89 | Peyton 90 | Melanie 91 | Gianna 92 | Isabelle 93 | Julia 94 | Valentina 95 | Nova 96 | Clara 97 | Vivian 98 | Reagan 99 | Mackenzie 100 | Madeline 101 | Brielle 102 | Delilah 103 | Isla 104 | Rylee 105 | Katherine 106 | Sophie 107 | Josephine 108 | Ivy 109 | Liliana 110 | Jade 111 | Maria 112 | Taylor 113 | Hadley 114 | Kylie 115 | Emery 116 | Adalynn 117 | Natalia 118 | Annabelle 119 | Faith 120 | Alexandra 121 | Ximena 122 | Ashley 123 | Brianna 124 | Raelynn 125 | Bailey 126 | Mary 127 | Athena 128 | Andrea 129 | Leilani 130 | Jasmine 131 | Lyla 132 | Margaret 133 | Alyssa 134 | Adalyn 135 | Arya 136 | Norah 137 | Khloe 138 | Kayla 139 | Eden 140 | Eliza 141 | Rose 142 | Ariel 143 | Melody 144 | Alexis 145 | Isabel 146 | Sydney 147 | Juliana 148 | Lauren 149 | Iris 150 | Emerson 151 | London 152 | Morgan 153 | Lilly 154 | Charlie 155 | Aliyah 156 | Valeria 157 | Arabella 158 | Sara 159 | Finley 160 | Trinity 161 | Ryleigh 162 | Jordyn 163 | Jocelyn 164 | Kimberly 165 | Esther 166 | Molly 167 | Valerie 168 | Cecilia 169 | Anastasia 170 | Daisy 171 | Reese 172 | Laila 173 | Mya 174 | Amy 175 | Teagan 176 | Amaya 177 | Elise 178 | Harmony 179 | Paige 180 | Adaline 181 | Fiona 182 | Alaina 183 | Nicole 184 | Genevieve 185 | Lucia 186 | Alina 187 | Mckenzie 188 | Callie 189 | Payton 190 | Eloise 191 | Brooke 192 | Londyn 193 | Mariah 194 | Julianna 195 | Rachel 196 | Daniela 197 | Gracie 198 | Catherine 199 | Angelina 200 | Presley -------------------------------------------------------------------------------- /Module7/Larger_Than_n7-6.py: -------------------------------------------------------------------------------- 1 | # Larger_Than_n7-6 2 | # In a program, write a function that accepts two arguments: a list, 3 | # and a number n. Assume that the list contains numbers. 4 | # The function should display all of the numbers in the list 5 | # that are greater than the number n. 6 | 7 | def main(): 8 | number=int(input('Enter the number: ')) 9 | list_num=[1,2,3,4,66,55,44,77,88,99,57] 10 | print('Numbers in the list taht are greater than',number) 11 | 12 | funct(list_num,number) 13 | 14 | def funct(list_num,number): 15 | for num in list_num: 16 | if num > number: 17 | print(num) 18 | 19 | main() 20 | -------------------------------------------------------------------------------- /Module7/Lottery_Number_Generator7-3.py: -------------------------------------------------------------------------------- 1 | # Lottery_Number_Generator2-7 2 | # Design a program that generates a seven-digit lottery number. 3 | # The program should generate seven random numbers, 4 | # each in the range of 0 through 9, and assign each number to a list element. 5 | # Then write another loop that displays the contents of the list. 6 | 7 | 8 | def main(): 9 | import random 10 | numbers=[0]*7 11 | for index in range(7): 12 | numbers[index]=random.randint(0,9) 13 | print('Here are your lottery numbers: ') 14 | for index in range(7): 15 | print(numbers[index],end='') 16 | print() 17 | 18 | main() 19 | -------------------------------------------------------------------------------- /Module7/Magic8Ball7_13.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IanaPanchyshena/Python-solutions-programming-exercises/011f1872d0d967cb85cdf1fdb8d6a460c4fabdd1/Module7/Magic8Ball7_13.py -------------------------------------------------------------------------------- /Module7/NameSearch7-8.py: -------------------------------------------------------------------------------- 1 | # NameSearch7-8 2 | # GirlNames.txt 3 | # This file contains a list of the 200 most popular names given to girls born 4 | # in the United States from the year 2000 through 2009. 5 | # BoyNames.txt 6 | # This file contains a list of the 200 most popular names 7 | # given to boys born in the United States from the year 2000 through 2009. 8 | # Write a program that reads the contents of the two files into two separate 9 | # lists. The user should be able to enter a boy’s name, a girl’s name, 10 | # or both, and the application will display messages indicating 11 | # whether the names were among the most popular. 12 | 13 | def get_names(file_name): 14 | list=[] 15 | f=open(file_name,'r') 16 | for line in f: 17 | list.append(line.rstrip('\n')) 18 | return list 19 | 20 | def main(): 21 | girl_names=get_names('GirlNames.txt') 22 | boy_names=get_names('BoyNames.txt') 23 | 24 | search=input("Enter a boy's or girl's name: ") 25 | found=0 26 | if search in girl_names: 27 | found=1 28 | print(search, "is the most popular girl's name") 29 | if search in boy_names: 30 | found=1 31 | print(search, "is the most popular boy's name") 32 | if found==0: 33 | print('Name not found') 34 | 35 | main() 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Module7/Number_Analysis_Program7-4.py: -------------------------------------------------------------------------------- 1 | # Number_Analysis_Program7-4 2 | # Design a program that asks the user to enter a series of 20 numbers. 3 | # The program should store the numbers in a list 4 | # then display the following data: 5 | # The lowest number in the list 6 | # The highest number in the list 7 | # The total of the numbers in the list 8 | # The average of the numbers in the list 9 | 10 | 11 | def main(): 12 | list_number=[] 13 | total=0 14 | for number in range (20): 15 | number=float(input('Enter the number '+format(number+1)+': ')) 16 | list_number.append(number) 17 | total+=number 18 | average=total/len(list_number) 19 | 20 | print('The lowest number in the list',min(list_number)) 21 | print('The highest number in the list',max(list_number)) 22 | print('The total of the numbers in the list', format(total,',.2f')) 23 | print('The average of the numbers in the list',format(average,',.2f')) 24 | 25 | main() 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Module7/Population Data7-9.py: -------------------------------------------------------------------------------- 1 | # Population Data7-8 2 | # USPopulation.txt 3 | # The file contains the midyear population of the United States, 4 | # in thousands, during the years 1950 through 1990. 5 | # The first line in the file contains the population for 1950, 6 | # the second line contains the population for 1951, and so forth. 7 | # Write a program that reads the file’s contents into a list. 8 | # The program should display the following data: 9 | # The average annual change in population during the time period 10 | # The year with the greatest increase in population during the time period 11 | # The year with the smallest increase in population during the time period 12 | 13 | import random 14 | def create_file(): 15 | file=open('USPopulation.txt','w') 16 | for line in range(40): 17 | number=random.randint(300000,350000) 18 | file.write(str(number)+'\n') 19 | file.close() 20 | 21 | def main(): 22 | #create_file() 23 | population_list=[] 24 | file=open('USPopulation.txt','r') 25 | 26 | 27 | 28 | main() 29 | -------------------------------------------------------------------------------- /Module7/RainfallStatistics7_2.py: -------------------------------------------------------------------------------- 1 | # Rainfall Statistics 7_2 2 | 3 | # Design a program that lets the user enter 4 | # the total rainfall for each of 12 months into a list. 5 | # The program should calculate and display the total rainfall for the year, 6 | # the average monthly rainfall, 7 | # the months with the highest 8 | # and lowest amounts. 9 | 10 | 11 | 12 | def main(): 13 | monthes = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] 14 | amount_list=[] 15 | total=0 16 | 17 | print('The total rainfall for each of 12 months.') 18 | 19 | for month in monthes: 20 | month_amount=float(input(month +': ') ) 21 | amount_list.append(month_amount) 22 | 23 | for amount in amount_list: 24 | total+=amount 25 | 26 | print('The total rainfall for the year',total) 27 | print('The avarage monthly rainfall',format(total/12,'.2f')) 28 | 29 | max_rainfall_month = max(amount_list) 30 | max_index = amount_list.index(max_rainfall_month) 31 | max_month = monthes[max_index] 32 | 33 | min_rainfall_month = min(amount_list) 34 | min_index = amount_list.index(min_rainfall_month) 35 | min_month = monthes[min_index] 36 | 37 | print('The month with highest rainfall', max_month) 38 | print('The month with lowest rainfall', min_month) 39 | 40 | 41 | main() 42 | -------------------------------------------------------------------------------- /Module7/Total_Sales7-1.py: -------------------------------------------------------------------------------- 1 | # Total Sales7-1 2 | # Design a program that asks the user to enter a store’s sales for each day 3 | # of the week. The amounts should be stored in a list. 4 | # Use a loop to calculate the total sales for the week and display the result. 5 | 6 | 7 | 8 | 9 | def main(): 10 | week_days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] 11 | amount_list=[] 12 | total=0 13 | print("Enter a store's sales for each day of the week.") 14 | 15 | for day_sale in week_days: 16 | day_sales=float(input(day_sale+': ') ) 17 | amount_list.append(day_sales) 18 | 19 | for day_sale in amount_list: 20 | total+=day_sale 21 | 22 | print('The total sales for the week',total) 23 | 24 | main() 25 | -------------------------------------------------------------------------------- /Module7/USPopulation.txt: -------------------------------------------------------------------------------- 1 | 343526 2 | 322411 3 | 342698 4 | 318654 5 | 341825 6 | 301531 7 | 344301 8 | 300443 9 | 343240 10 | 322896 11 | 311111 12 | 318688 13 | 336484 14 | 345249 15 | 337267 16 | 324938 17 | 309899 18 | 340300 19 | 314925 20 | 349333 21 | 301889 22 | 328579 23 | 342816 24 | 331642 25 | 331581 26 | 311897 27 | 317816 28 | 300493 29 | 326556 30 | 337541 31 | 348723 32 | 327087 33 | 314006 34 | 345150 35 | 342044 36 | 348622 37 | 318871 38 | 306481 39 | 309274 40 | 304355 41 | -------------------------------------------------------------------------------- /Module7/charge_accounts.txt: -------------------------------------------------------------------------------- 1 | 2222222 2 | 1111111 3 | 8888888 4 | 7777777 5 | 6666666 6 | 4444444 7 | 2222222 8 | -------------------------------------------------------------------------------- /Module7/user_answers.txt: -------------------------------------------------------------------------------- 1 | A 2 | B 3 | A 4 | A 5 | D 6 | B 7 | C 8 | A 9 | C 10 | B 11 | A 12 | B 13 | C 14 | A 15 | D 16 | A 17 | B 18 | B 19 | D 20 | A --------------------------------------------------------------------------------