Source code for AutomateTheBoringStuff.Ch01.P1_basics

"""Basics

This program performs basic Python instructions.

"""


[docs]def main(): # Expressions print(2 + 2) print(2 + 3 * 6) print((2 + 3) * 6) print(48565878 * 578453) print(2 ** 8) print(23 / 7) print(23 // 7) print(23 % 7) print(2 + 2) print((5 - 1) * ((7 + 1) / (3 - 1))) # Uncomment to see what happens #print(5 + ) #print(42 + 5 + * 2) # The Integer, Floating-Point, and String Data Types #print("Hello world!) # Uncomment to see what happens print("Alice" + "Bob") #print("Alice" + 42) # Uncomment to see what happens print("Alice" * 5) # Uncomment to see what happens #print("Alice" * "Bob") #print("Alice" * 5.0) # Storing Values in Variables spam = 40 print(spam) eggs = 2 print(spam + eggs) print(spam + eggs + spam) spam = spam + 2 print(spam) spam = "Hello" print(spam) spam = "Goodbye" print(spam) # The len() Function print(len("hello")) print(len("My very energetic monster just scarfed nachos.")) print(len('')) #print("I am" + 29 + " years old.") # Uncomment to see what happens # The str(), int(), and float() Functions print(str(29)) print("I am " + str(29) + " years old.") print(str(0)) print(str(-3.14)) print(int("42")) print(int("-99")) print(int(1.25)) print(int(1.99)) print(float("3.14")) print(float(10)) spam = input("Type 101 here: ") # Type 101 when prompted print(spam) spam = int(spam) print(spam) print(spam * 10 / 5) # Uncomment to see what happens #print(int("99.99")) #print(int("twelve")) print(int(7.7)) print(int(7.7) + 1)
# If P1_basics.py is run (instead of imported as a module), call # the main() function: if __name__ == '__main__': main()