Learn Python – NOTES 1 – 10

https://edube.org/login – Python 3 or CPython
Programming tool is IDLE

https://docs.python.org/3/library/functions.html

# Sample Python Program 01

# Get user input for name
name = input(“Enter your name: “)
# Get user input for age
age = input(“Enter your age: “)
# Convert age to an integer
age = int(age)
# Print a personalized greeting
print(f”Hello, {name}! You are {age} years old.”)

# Sample Python Program 02

# Using the f function
print(f”Hello, {second}! You are {first} years old.”)
print(“Hello, {second}! You are {first} years old.”)

# Sample Python Program 03

# Using the end and sep functions within print()
print(“Programming”,”Essentials”,”in”,sep=”***”,end=”…”)
print(“Python”)
# THIS WILL DISPLAY – Programming***Essentials***in…Python

# Sample Python Program 04

# PLAYING AROUND WITH end and sep
print(” *”)
print(” * *”)
print(” * *”)
print(” * *”)
print(‘*** ***’)
print(” * *”)
print(” * *”)
print(” *****”)
# *
# * *
# * *
# * *
# *** ***
# * *
# * *
# *****

# Sample Python Program 05

# Octals and Hexidecimals and Base 10
print(0o123)
print(0x123)
print (123)
print (“123”)

# Sample Python Program 06

# Forcing quotes to appear in print
print("I like \"Monty Python\"")
print("I like 'Monty Python'")
print('I like "Monty Python"')
print("I like \'Monty Python\'")

# Sample Python Program 07

# print three lines with a single line of code

“I’m” ,
“”learning”” ,
“””Python”””

One long string
print(” \”I\’m\”      \n \”\”learning\”\”       \n \”\”\”Python\”\”\” “)
Three shorter strings
print(“\”I’m\”” , “\n\”\”learning\”\”” , “\n\”\”\”Python\”\”\””)
Using the SEP function
print(“\”I’m\”” , “\”learning\”\”” , “\”\”Python\”\”\””,sep=”\n”)

# Sample Python Program 08

# Try to understand the ** operator
print ((2**0) + (2**1) + (2**3))
print (2**0)
print (2**1)
print (2**3)

print ((2**0) + (2**1) + (2**2) + (2**3))
print (2**0)
print (2**1)
print (2**2)
print (2**3)

# Sample Python Program 09

# Mathematical Operators
+    -    *    /    //    %    **

# Sample Python Program 10
#Significant digits

print(2 ** 3) # this results in an integer
print(2 ** 3.) # this results in a float
print(2. ** 3) # this results in a float
print(2. ** 3.) # this results in a float

Division is always a float, unless…
print(6 / 3)
print (int(6 / 3))   # or
print(6 // 3)     # (forces integer as a result – TRUNCATES – does not round
print(6 / 3.)
print(6. / 3)
print(6. / 3.)