Python Tutorial for Beginners - 2. Integers and Floats - Working with Numeric Data

  1. Run Code 1 in Python
  2. Run Code 2 in Python
  3. Run Code 3 in Python
  4. Run Code 4 in Python
  5. Run Code 5 in Python
  6. Run Code 6 in Python
  7. Run Code 7 in Python
  8. Run Code 8 in Python
  9. Run Code 9 in Python
  10. Run Code 10 in Python
  11. Run Code 11 in Python
  12. Run Code 12 in Python
  13. Run Code 13 in Python

Run Code 1 in Python

# file: 'app1.py'
# Arithmetic Operators:
# Addition:       3 + 2
# Subtraction:    3 - 2
# Multiplication: 3 * 2
# Division:       3 / 2
# Floor Division: 3 // 2
# Exponent:       3 ** 2
# Modulus:        3 % 2

num = 3

print(type(num))

Run Code 2 in Python

# file: 'app2.py'
num = 3.14

print(type(num))

Run Code 3 in Python

# file: 'app3.py'
print (3+2)
print (3-2)
print (3*2)
print (3/2)
print (3//2)
print (3**2)

Run Code 4 in Python

# file: 'app4.py'
print (2 % 2)
print (3 % 2)
print (4 % 2)
print (5 % 2)

Run Code 5 in Python

# file: 'app5.py'
print (3 * 2 + 1)
print (3 * (2 + 1))

Run Code 6 in Python

# file: 'app6.py'
num = 1
num = num +1

print(num)

Run Code 7 in Python

# file: 'app7.py'
num = 1
num += 1

print(num)

Run Code 8 in Python

# file: 'app8.py'
num = 1
num += 10

print(num)

Run Code 9 in Python

# file: 'app9.py'
num = 1
num *= 10

print(num)

Run Code 10 in Python

# file: 'app10.py'
print(abs(-3))
print(round(3.75))
print(round(3.75, 1))

Run Code 11 in Python

# file: 'app11.py'
# Comparisons:
# Equal:            3 == 2
# Not Equal:        3 != 2
# Greater Than:     3 > 2
# Less Than:        3 < 2
# Greater or Equal: 3 >= 2
# Less or Equal:    3 <= 2


num_1 = 3
num_2 = 2

print(num_1 == num_2)
print(num_1 != num_2)
print(num_1 < num_2)
print(num_1 > num_2)
print(num_1 <= num_2)
print(num_1 >= num_2)

Run Code 12 in Python

# file: 'app12.py'
num_1 = '100'
num_2 = '200'

print(num_1 + num_2)

Run Code 13 in Python

# file: 'app13.py'
num_1 = '100'
num_2 = '200'

num_1 = int(num_1)
num_2 = int(num_2)

print(num_1 + num_2)

Comments 💬