''' Purpose: demonstrate int and float numeric input processing ''' # get inputs x_reply = input( 'Enter base (integer): ' ) n_reply = input( 'Enter exponent (decimal): ' ) # huh = x_reply ** n_reply # print( huh ) # this willllllll blow up # x_reply and n_reply are STRINGS!!!!! # You can't do math with number strings. # Key Takeaway again: input( prompt ) hands back user input as a STRING. print() # convert inputs to numerics x = int( x_reply ) # cast string x_reply to get an int n = float( n_reply ) # cast string n_reply to get a decimal # int( x ) and float( x ) - convert whatever x is to an int and float # respectively. They only take in ONE thing to convert. # Again, you can't do int('3 2') or something. # You can't do int('3.5') because the string is not a string of an int. # You can do int('3') or float('3.5') or float('3') but not int('3.5'). # !! int() cannot convert a decimal string to an integer! ''' INTS AND FLOATS ''' # Please make sure you know how this works! :) # USING INT for strings vs. numbers # int('3') -> 3 # convert string integer to number # int(3.871298734891754) -> 3 # chop off decimal portion to get # integer # int produces integers and float produces decimal numbers. # float('3.5') -> 3.5 # float('3') -> 3.0 # float(3) -> 3.0 # VOCAB TERM FOR YOU ALL: numeric string # A numeric string is a string representation of a number i.e. '3' or '512' # THIS TERM HAS SHOWN UP ON HOMEWORKS AND TESTS # In this program, the base must be an integer and the # exponent can be either because again float('3') or float('3.5') work # since integers are a subset of decimals but NOT vice versa. # compute x to the nth power value = x ** n # display result print( value )