#!/usr/bin/env python # coding: utf-8 # In[9]: # Variables are called this because their value can change dollars=1.56 print('I have',dollars,'in my account.') dollars=32.6 print('I now have',dollars,'in my account.') # All variables have a "type" # check the type of the dollars variable: # use the type() function to do this: print(type(dollars)) # we saw dollars is a "float" -- which means it had a decimal point in it governor='Jim Justice' print(type(governor)) # now integer type zloty=5 # check the type of zloty print(type(zloty)) # now an example where it can be confusing: lei=5.0 print(type(lei)) # Question: what is the type when you add them? newmoney=zloty+lei print('the type of the sum is') print(type(newmoney)) # In[25]: # Section 2.6 -- keyboard input # Get a user's name: #name=input('What is your name?') #print('Your name is',name) #get first name #firstname=input('What is your first name?') #get last name #lastname=input('What is your last name?') # print a greeting #print('Welcome',firstname,lastname,'!') #this gives a type error: #notanumber='5' #print(3.2*notanumber) # FACT: input always assigns a string #hours_string=input('How many hours did you work?') #print('The type of hours_string is',type(hours_string)) # typecasting: changing of a type #hours=int(hours_string) #print('The type of hours is',type(hours),'and its value is',hours) # same but more efficient hours=int(input('How many hours did you work?')) print('You worked',hours,'hours, and the type of hours is',type(hours))