Python Data Types, User Input, and Positional Number Systems
Academic Course Information and Context
- Student Name: Alexandra Lozano.
- Course: Computing Safety Mini Course.
- Platform and Curriculum: Digital Literacy - Safety and Security, hosted on edube.org.
- Identified User Handles: @ILRO5212010 and Allr@05212010.
- Session Dates Recorded: October 14, 2026 (10/14/2026), October 15, 2026 (10/15/2026), and October 19, 2026 (10/19/2026).
- Core Subject Matter: Input and Type Conversion (annotated as Input/Type Carasiam), scientific notation, and positional number systems in Python.
- Definition of the
input() Function:- Operates as a built-in function call designed to pause program execution and accept input from the user.
- Behavior: Collects data entered by the user through the standard input console and automatically converts the entered data into a string data type (
str).
- Function Arguments and Syntax:
- The argument passed into
input() is optional. - When an argument is supplied, it acts as a prompt that displays a message directly to the user.
- Syntax Example:
input("What is your name: "), where the string "What is your name: " is the argument that prints to the console before user input is received.
Data Type Conversions and Operations
- String Conversion (
str()):- Takes an argument of a non-string or string type and converts it into a string (
str). - Example:
str(4) evaluates to the string '4'.
- Integer Conversion (
int()):- Converts a numeric value or a compatible string representation into a standard integer (
int). - Examples of valid conversions:
int(4) evaluates to the integer 4.int('41') evaluates to the integer 41.int('7') evaluates to the integer 7.int('5') evaluates to the integer 5.- Error Handling on Non-Numeric Literals: Attempting an integer conversion on an alphabetical string such as
int('Junely') causes a runtime error, as non-numeric string literals cannot be converted to an integer.
- Floating-Point Conversion (
float()):- Converts an integer, numeric value, or compatible string into a floating-point number (
float). - Example:
float(4) evaluates to 4.0.
- Concatenation versus Arithmetic Addition Case Study:
- Default behavior without type conversion:
- Code:
x = input("Enter a number: ") (User enters 7, variable x stores '7')y = input("Enter a number: ") (User enters 5, variable y stores '5')print("The Sum of your number is: ", x + y)
- Evaluation: Because
x and y are string variables, the + operator executes string concatenation rather than numerical addition, yielding '75'. - Corrected behavior utilizing explicit type conversion:
- Code:
x = int(x) (Converts '7' to the integer 7)y = int(y) (Converts '5' to the integer 5)print(x + y)
- Evaluation: Because
x and y are explicitly converted to integers, the + operator executes mathematical addition, yielding 7+5=12.
Scientific and Exponential Notations
- Representation of Large Numerical Quantities:
- Standard decimal notation: 156,000,000 (annotated as
1.5600,000.). - Scientific E-notation:
1.56e8. - Standard scientific notation: 1.56×108.
- Representation of Small Fractional Numerical Quantities:
- Standard decimal notation: 0.00000023 (annotated as
.0000002.3). - Scientific E-notation:
2.3e-7. - Standard scientific notation: 2.3×10−7.
- Expression Fragment Notated:
6-23t56+00.
Number Systems and Representation Prefixes
- Python Default Display Format:
- Python prints numerical output in decimal (Base 10) by default.
- Positional Number Systems Overview:
- Decimal:
- Base 10.
- Utilizes digits: 0,1,2,3,4,5,6,7,8,9.
- Binary:
- Base 2.
- Prefix indicator in Python:
0b or 0B. - Utilizes digits: 0,1.
- Octal:
- Base 8.
- Prefix indicator in Python:
0o or 0O. - Utilizes digits: 0,1,2,3,4,5,6,7.
- Hexadecimal:
- Base 16.
- Prefix indicator in Python:
0x or 0X. - Utilizes digits 0 through 9 and letters A through F (or lowercase a through f).
- Alphanumeric character values:
- A=10
- B=11
- C=12
- D=13
- E=14
- F=15
- Python Built-in Base Conversion Functions:
bin(): Converts an integer into a binary string literal with the 0b prefix.oct(): Converts an integer into an octal string literal with the 0o prefix.hex(): Converts an integer into a hexadecimal string literal with the 0x prefix.
Numerical Base Conversions and Algorithms
- Binary to Decimal Conversion:
- Instruction:
print(0b1101010). - Binary Value:
1101010. - Positional place value weights (powers of 2 from right to left):
- 26=64
- 25=32
- 24=16
- 23=8
- 22=4
- 21=2
- 20=1
- Step-by-step expansion:
- (1×64)+(1×32)+(0×16)+(1×8)+(0×4)+(1×2)+(0×1)
- 64+32+8+2=106
- Subtotal calculation check: 64+32=96; 8+2=10; 96+10=106.
- Decimal to Binary Conversion via Repeated Division by 2:
- Evaluated command:
print(bin(100)). - Division steps recording quotients and remainders (R):
- 100÷2=50 R 0
- 50÷2=25 R 0
- 25÷2=12 R 1
- 12÷2=6 R 0
- 6÷2=3 R 0
- 3÷2=1 R 1
- 1÷2=0 R 1
- Reading the remainders sequentially from the last operation to the first (bottom to top):
1100100. - Binary result:
0b1100100.
- Hexadecimal to Decimal Conversion:
- Instruction:
print(0x3b). - Hexadecimal Value:
3b. - Positional place values (powers of 16):
- 161=16
- 160=1
- Character mapping: b=11.
- Step-by-step expansion:
- (3×16)+(11×1)
- 48+11=59
- Decimal output: 59.
- Hexadecimal multi-digit positional weights (e.g., representation for
AAA): - 162=256
- 161=16
- 160=1
- Decimal to Hexadecimal Conversion via Repeated Division by 16:
- Conversion of decimal 1000:
- 1000÷16=62 R 8
- 62÷16=3 R 14 (decimal remainder 14 maps to hexadecimal digit
e or E) - 3÷16=0 R 3
- Reading remainders from bottom to top:
3e8. - Hexadecimal representation:
0x3e8.
- Octal to Decimal Conversion:
- Instruction:
print(0o457). - Octal Value:
457. - Positional place value weights (powers of 8):
- 82=64
- 81=8
- 80=1
- Step-by-step expansion:
- (4×64)+(5×8)+(7×1)
- 256+40+7
- Intermediate step: 256+40=296
- Final sum: 296+7=303
- Decimal output: 303.
- Decimal to Octal Conversion via Repeated Division by 8:
- Evaluated command:
print(oct(99)). - Division steps recording quotients and remainders (R):
- 99÷8=12 R 3
- 12÷8=1 R 4
- 1÷8=0 R 1
- Reading remainders from bottom to top:
143. - Octal result:
0o143. - Verification via positional expansion:
- (1×64)+(4×8)+(3×1)
- 64+32+3=99.