CS106 Summer 2026 Michael Eckmann Lab 02 July 02, 2026 ================== Purpose: Experience writing programs to compute something useful (includes getting user input, doing arithmetic operations, using if/elif/else and outputting results). Also use of random numbers and while loops. =================== 1. Write a program named randcharacter.py that generates a random "character". Utilize 3 calls to random.randint and 3 sets of if/else or if/elif/.../else structures. Select one of each of these to store based on the random integers generated: First Name: Jane, Fred, Pat, Sean Descriptive phrase: "the conquerer", "the great", "the impaler" Type: Hero, Villan Use three variables to store the 3 random integers. Use a variable to store first name, a variable to store descriptive phrase and a variable to store type. Use if/else and if/elif/.../else to assign one of the values into each of the variables (first name, descriptive phrase, and type) based on the randints generated. Have one print statement at the end that prints out the character in the following format: ____ ___________ is a _______ e.g. some possibilities of what can print out are: Jane the great is a Hero Pat the conquerer is a Villan Sean the impaler is a Hero Note well: each of the four names should be equally likely to be generated, each of the three phrases should be equally likely and finally both of the types should be equally likely. =================== 2. Rewrite the following lines of code in a different way but have their result be the same. (If you need to, put them in a program with some values and print statements to test them out.) a. y = y + 1 b. salary *= 2.5 c. if not (y != 5): d. if name == 'Skidmore' and 7 == 7: e. if False or name == 'Skidmore': =================== 3. As activity directory at Lake LazyDays Resort, it is your job to suggest appropriate activities to guests based on the weather: temp >= 80: swimming 60 <= temp < 80: tennis 40 <= temp < 60: golf temp < 40: skiing a. Write a program (with name suggestactivity.py) that prompts the user for a temperature, then prints out the activity appropriate for that temperature. You should use if/elif/elif/.../else structure so that your conditions are no more complex than necessary. That is, do NOT use the logical operators: and, or for this part. b. Modify your program so that if the temperature is greater than 95 or less than 20, it prints "Visit our shops!". You should use a logical operator for this condition. For other temperatures print the activity as before. You only need to submit the revised (b) version. =================== 4. Write a program named (raise.py) to determine the raise and new salary for an employee. The input to the program includes the current annual salary for the employee and a letter indicating the performance rating (a=excellent, b=good, and c=poor). An employee with a rating of a will receive a 6% raise, an employee with a rating of b will receive a 4% raise, and one with a rating of c will receive a 1.5% raise. Note: you do not need to check if the rating is c, if it is not a or b then the raise should be 1.5%. Example run of your program: Enter the current salary: 50000 Enter the performance rating: a Amount of your raise: $3000.0 Your new salary: $53000.0 The first two lines above are for input, the next two are only output. =================== 5. Write a program named numberstats.py that asks the user for positive numbers, until s/he enters -1. Then print the sum of all the numbers, the average of all the numbers and the smallest number. e.g. Enter a number or -1 to quit: 5 Enter a number or -1 to quit: 3 Enter a number or -1 to quit: 11 Enter a number or -1 to quit: 9 Enter a number or -1 to quit: 6 Enter a number or -1 to quit: 15 Enter a number or -1 to quit: 21 Enter a number or -1 to quit: -1 Sum of the numbers you entered: 70 Average of the numbers you entered: 10 Smallest number entered: 3 Notice that the -1 is not used in the sum, average or smallest number, just to end the input. =========== submit: randcharacter.py answers to question 2 suggestactivity.py raise.py numberstats.py