#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 9/13/2022 DS 2000 Lecture 2 - print, input, type casting, round Logistics: - Your first due dates will be on Friday (9/16)! - Quiz 1 (will be released today @ 4:30pm, due Friday @ 9:50 AM) - Homework 1 (due Friday @ 9pm) """ """ Warm-up --- Question: What is the value of the variable "x" at the end of the following lines of code? x = 10 x = 10 * 2 x = x + 10 print(x) A. 10 B. 20 C. 30 D. 40 E. Error """ """ Warm-up --- (Deitel & Deitel 2.3) Question: What does the ** operator do? """ """ review: python "commands" ---- Last lecture: we learned about using the print() command to display information to the user. print() is actually a kind of python *function*. function: a pre-packaged group code that does one job for you. python provides a number of very useful functions. syntax: in python, functions *always* are used by writing the function name and then a set of parentheses () In general, to use a function, you need to know three things: 1. Does this function give me any information back? 2. what is this function's name? 3. what information does this function need to run? For print(): 1. Does this function give me any information back? 2. what is this function's name? 3. what information does this function need to run? Vocabulary: - function - arguments/parameters """ """ Getting fancy with print() ---- (Deitel & Deitel 2.4) To print multiple pieces of information on the same line, we can pass multiple parameters to the print() function. """ # print() examples """ input() ---- (Deitel & Deitel 2.6) input() is a python *function*. Its job is to get information from the user. Let's answer the three function questions first: 1. Does this function give me any information back? 2. what is this function's name? 3. what information does this function need to run? Vocabulary: - return/return value """ # input() examples """ Question: What is the data type of "answer" after the following lines of code? A. """ """ data types ---- all *values* in python have a *data type* string: int: float: There are others, but these are the ones that we'll focus on for now! """ """ type conversion ---- string, int, and float all have special python functions that convert values of a different type into the target type. For example, we have an int() function: 1. Does this function give me any information back? 2. what is this function's name? 3. what information does this function need to run? """ # int() examples # str() examples # w/o return examples/questions """ input() + types --- """ """ Example problems from last Friday! """ """ Example problem 1: Write a program that asks the user how old they are, then prints this number out. """ age = 31 print("Your age:") print(age) """ Example problem 2: Write a program that asks the user how many apples they would like to eat each day, then calculates how many apples they should buy per week. """ apples_per_day = 3 apples_per_week = apples_per_day * 7 print("you should buy:") print(apples_per_week) """ round() --- """ """ Summary (very brief) --- Functions to be familiar with: - print() - input() - int() - float() - str() - round() We also learned some more vocabulary: - function - parameter/argument - return/return value """