Hello, CS 111! lab
Welcome to CS 111! This is a lab activity, not an assignment. Therefore, it's not required that you complete it or hand it in. However, the concepts in this lab will be useful when you go to complete the first homework assignment (and will be useful for exams down the road), so I'd encourage you to put in a serious effort on it in class, and to consider finishing any remaining parts outside of class.
Exercise 0
We just did this part together, but here is a reminder:
This link has screenshots that correspond to these instructions.
- Mount the COURSES drive by double clicking the courses Desktop icon (if you didn't use the checkbox when you logged in)
- Create a new folder in your STUWORK folder called
Lab0 - Open VSCode
- Click and drag your
Lab0folder to the VSCode window to open it - Create a new file named
hello.py - In the menu under Terminal, click New Terminal to open a terminal window.
Exercise 1: Hello, CS111!
For this exercise, predict the output and then run each of the following commands in VSCode.
(Copy and paste each part of the code into your hello.py file. Then, save the file. In the
terminal window, type python3 hello.py to run the program you've created.)
# 1a print("Hello, CS111!") ## Prints: FILL IN HERE # 1b print("Hello", "CS111!") ## Prints: FILL IN HERE # 1c print("Hello") print() print("CS111!") ## Prints: FILL IN HERE
Exercise 2: Getting user input
In this exercise, you'll practice using the input() function to ask the user for input.
Part a: getting multiple inputs
We can use the input function to ask the user for multiple inputs.
print("Please type 4 numbers (ints or floats), hitting return/enter after each.") num1 = input() num2 = input() num3 = input() num4 = input() print("Their product is:", float(num1) * float(num2) * float(num3) * float(num4)) ## This program does the following: FILL IN HERE
What do you think will happen when this program runs? Predict the result and then type it up in VSCode to find out.
Part b: writing a function
We can include a parameter to input to prompt the user. Type the following
lines of code in VSCode and observe the output.
# 2b-1: Get user input animal = input("What is your favorite type of animal? ") print("Your favorite type of animal is:", animal) # 2b-2: Write and use a function to congratulate the user def congratulate(firstName): print("Congratulations,", firstName, "!") congratulate("Sirius") # one of my cats :) congratulate("Stella") # my other cat congratulate(Anna) # what's different here? ## This program does the following: FILL IN HERE
Food for thought: How would you add punctuation after the name, without a space in between?
Anna's acknowledgements
This lab was originally created by Tanya Amert.