Name address value usrlocalbinpython3 converts

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: one statement per line 16 Comments Comments start with #, they can be anywhere in the line Comments are ignored by the compiler/Interpreter and exist for human eyes only #!/usr/local/bin/python3 # Converts temperatures from Fahrenheit to Celsius # Ask user for input F = float( input("Please enter a temperature in Fahrenheit: ") ) # Do the conversion C = (F-32)*5/9 # Print the result print("The temperature in Celsius is: ", C ) 17 Literals (= constants) String constant Literal = constant #!/usr/local/bin/python3 # Converts temperatures from Fahrenheit to Celsius # Ask user for input F = float( input("Please enter a temperature in Fahrenheit: ") ) # Do the conversion C = (F-32)*5/9 # Print the result print("The temperature in Celsius is: ", C ) Numeric constant 18 6 13 ­09 ­10 Variables Variables allow one to refer to values using easy-to-remember names. name address value #!/usr/local/bin/python3 # Converts temperatures from Fahrenheit to Celsius # Ask user for input F = float( input("Please enter a temperature in Fahrenheit: ") ) # Do the conversion C = (F-32)*5/9 # Print the result print("The temperature in Celsius is: ", C ) 19 Memory Addresses 001 12 004 1304 002 27 005 54 003 8 006 99 How much can we store? In each drawer we can store a word Word length?: •  32 bit CPUs 32 bit words •  64 bit CPUs 64 bit words •  8 bits = 1 byte •  32 bits = 4 bytes •  64 bits = 8 bytes Contents 20 Variables are beVer than memory addresses • What is the problem with using memory addresses?   Hard to remember   We can confuse different memory loca3ons   We have to decide about the loca3on • Variables address these issues   Variable = Name + Address   The compiler/interpreter assigns the addresses •  We don’t have to worry about this!   Programmer’s perspec3ve: •  Create variable by introducing a name •  Use the variable   A variable represents what is stored at the address 21 7 13 ­09 ­10 Variables Name Address A 003 Age 005 Height 12 004 1304 27 005 5...
View Full Document

Ask a homework question - tutors are online