basil[~]$ python3 Python 3.6.5 (default, Apr 1 2018, 05:46:30) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> range(5) range(0, 5) >>> n = 5 >>> range(n) range(0, 5) >>> list(range(n)) [0, 1, 2, 3, 4] >>> list(range(0,5)) [0, 1, 2, 3, 4] >>> list(range(1,6)) [1, 2, 3, 4, 5] >>> list(range(1,10)) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(1,11)) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> list(range(1,11,2)) [1, 3, 5, 7, 9] >>> list(range(2,12,2)) [2, 4, 6, 8, 10] >>> print("range is", list(range(2,12,2))) range is [2, 4, 6, 8, 10] >>> import random >>> random.randam() Traceback (most recent call last): File "", line 1, in AttributeError: module 'random' has no attribute 'randam' >>> random.random() 0.5331456998367317 >>> random.random() 0.8826946322506061 >>> random.random() 0.2148781776083334 >>> random.random() 0.6945661260730926 >>> random.random() 0.5190255833625674 >>> random.random() 0.19080905101513523 >>> random.random() 0.2805727469723869 >>> random.random() 0.8838220348702058 >>> help random.random() File "", line 1 help random.random() ^ SyntaxError: invalid syntax >>> random.randrange(5) 1 >>> random.randrange(5) 3 >>> random.randrange(5) 4 >>> random.randrange(5) 3 >>> random.randrange(0,5) 0 >>> random.randrange(0,5) 3 >>> random.randrange(0,5) 4 >>> random.randrange(0,5) 2 >>> random.randrange(0,5) 1 >>> random.randrange(0,5) 2 >>> choice = [1,2,3,4] >>> choice [1, 2, 3, 4] >>> random.choice(choice) 3 >>> random.choice(choice) 2 >>> random.choice(choice) 2 >>> random.choice(choice) 1 >>> random.choice(choice) 2 >>> random.choice(choice) 2 >>> random.choice(choice) 2 >>> random.choice(choice) 2 >>> random.choice(choice) 1 >>> random.choice(choice) 4 >>> random.choice(choice) 1 >>> random.choice(choice) 4 >>> random.choice(choice) 2 >>> random.choice("abcd") 'd' >>> >>> random.choice("abcd") 'a' >>> random.choice("abcd") 'c' >>> random.choice("abcd") 'a' >>> random.choice("abcd") 'b' >>> random.choice("abcd") 'a' >>> random.choice(['a', 'b', 'c', 'd']) 'd' >>> random.choice(['a', 'b', 'c', 'd']) 'd' >>> random.choice(['a', 'b', 'c', 'd']) 'a' >>> random.choice(['a', 'b', 'c', 'd']) 'c' >>> random.choice(['a', 'b', 'c', 'd']) 'b' >>> random.choice(['a', 'b', 'c', 'd']) 'd' >>> random.choice(['a', 'b', 'c', 'd']) 'c' >>> random.choice(['a', 'b', 'c', 'd']) 'b' >>> import math >>> math.sqrt(5) 2.23606797749979 >>> random.random() 0.6673304137972574 >>> random.random() 0.17333614414895515 >>> num = 11 >>> print("The number of swans is", num) The number of swans is 11 >>> name = "Hermes" >>> speed = 2/3 >>> Hermes Traceback (most recent call last): File "", line 1, in NameError: name 'Hermes' is not defined >>> name 'Hermes' >>> speed 0.6666666666666666 >>> print("%s brings Zeus %d at speed %f"%(name, num, speed)) Hermes brings Zeus 11 at speed 0.666667 >>> print("%s brings Zeus %d at speed %f"%(name, speed, num)) Hermes brings Zeus 0 at speed 11.000000 >>> print("%s brings Zeus %d at speed %.2f"%(name, num, speed)) Hermes brings Zeus 11 at speed 0.67 >>> print(name, "brings Zeus", num, "at speed", speed) Hermes brings Zeus 11 at speed 0.6666666666666666 >>> print(name, "brings Zeus", num, "at speed", speed) >>> print(name, "brings Zeus", num, "at speed", speed) >>> print(name, "brings Zeus", num, "at speed", speed) Hermes brings Zeus 11 at speed 0.6666666666666666 >>> basil[~]$ basil[~]$ basil[~]$ basil[~]$ python3 Python 3.6.5 (default, Apr 1 2018, 05:46:30) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> range(5) range(0, 5) >>> list(range(5)) [0, 1, 2, 3, 4] >>> list(range(1,5)) [1, 2, 3, 4] >>> list(range(1,10,2)) [1, 3, 5, 7, 9] >>> list(range(2,10,2)) [2, 4, 6, 8] >>> import random >>> random.random() 0.7724892301327374 >>> random.random() 0.2600625942338872 >>> random.random() 0.7490330304638733 >>> random.random() 0.9962098389828166 >>> random.random() 0.5066303495589144 >>> random.random() 0.7066398872106565 >>> random.random() 0.8326752863890612 >>> random.random() 0.46001888105485844 >>> random.random() 0.5946628519936595 >>> random.random() 0.1673962340412518 >>> random.random() 0.14906138413127368 >>> random.random() 0.670057233966382 >>> random.random() 0.597252385886957 >>> random.randrange(0,5) 1 >>> random.randrange(0,5) 0 >>> random.randrange(0,5) 0 >>> random.randrange(0,5) 1 >>> random.randrange(0,5) 4 >>> random.randrange(0,5) 2 >>> random.randrange(0,5) 4 >>> random.randrange(0,5) 1 >>> random.randrange(0,5) 4 >>> random.randrange(0,5) 0 >>> random.randrange(0,5) 0 >>> random.randrange(0,5) 3 >>> choices = [1,2,3,4] >>> random.choice(choices) 3 >>> random.choice(choices) 2 >>> random.choice(choices) 3 >>> random.choice(choices) 3 >>> random.choice(choices) 2 >>> random.choice(choices) 1 >>> random.choice(choices) 4 >>> random.choice(choices) 1 >>> random.choice(choices) 2 >>> random.choice(choices) 2 >>> random.choice(choices) 1 >>> random.choice(choices) 3 >>> random.choice(choices) 2 >>> choices = ["a", "b", "c"] >>> random.choice(choices) 'b' >>> random.choice(choices) 'b' >>> random.choice(choices) 'c' >>> random.choice(choices) 'c' >>> random.choice(choices) 'c' >>> random.choice(choices) 'b' >>> random.choice(choices) 'a' >>> random.choice("apple") 'e' >>> random.choice("apple") 'p' >>> random.choice("apple") 'p' >>> random.choice("apple") 'p' >>> random.choice("apple") 'a' >>> random.choice("apple") 'p' >>> random.choice("apple") 'p' >>> random.choice("bcd") 'b' >>> random.choice("bcd") 'b' >>> >>> random.choice("bcd") 'd' >>> random.choice("bcd") 'd' >>> >>> print("Number of swans " File "", line 1 print("Number of swans ^ SyntaxError: EOL while scanning string literal >>> print("Number of swans", 11) Number of swans 11 >>> num = 11 >>> print("Number of swans", num) Number of swans 11 >>> name = "Hermes" >>> speed = 2/3 >>> speed 0.6666666666666666 >>> name 'Hermes' >>> num 11 >>> "%s runs at speed %f to give %d swans to Zeus"%(name, speed, num) 'Hermes runs at speed 0.666667 to give 11 swans to Zeus' >>> "%s runs at speed %f to give %d swans to Zeus"%(name, num, speed) 'Hermes runs at speed 11.000000 to give 0 swans to Zeus' >>> "%s runs at speed %.2f to give %d swans to Zeus"%(name, speed, num) 'Hermes runs at speed 0.67 to give 11 swans to Zeus' >>> print(name, "runs at speed ", speed, "to give", num, "swans to Zeus") Hermes runs at speed 0.6666666666666666 to give 11 swans to Zeus >>>