|
| 1 | +from sys import argv |
| 2 | + |
| 3 | +print("How old are you?", end24=' ') |
| 4 | +age = input() |
| 5 | +print("How tall are you?", end=' ') |
| 6 | +height = input() |
| 7 | +print("How much do you weigh?", end=' ') |
| 8 | +weight = input() |
| 9 | + |
| 10 | +print(f"So, you're {age} old, {height} tall and {weight} heavy.") |
| 11 | + |
| 12 | +print("After this you need to open ### Open file and print") |
| 13 | + |
| 14 | +filename = argv |
| 15 | + |
| 16 | +txt = open(filename) |
| 17 | +print("Here's your file {filename}:") |
| 18 | +print(txt.read()) |
| 19 | + |
| 20 | +print("Type the filename again:") |
| 21 | +file_again = input("> ") |
| 22 | + |
| 23 | +txt_again = open(file_again) |
| 24 | + |
| 25 | +print(txt_again()) |
| 26 | +### |
| 27 | + |
| 28 | + |
| 29 | +print('Let\'s practice everything.') |
| 30 | +print('You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.') |
| 31 | + |
| 32 | +poem = """ |
| 33 | +\tThe lovely world |
| 34 | +with logic so firmly planted |
| 35 | +cannot discern \n the needs of love |
| 36 | +nor comprehend passion from intuition |
| 37 | +and requires an explanation |
| 38 | +\n\t\twhere there is none. |
| 39 | +""" |
| 40 | + |
| 41 | +print("--------------") |
| 42 | +print(poem) |
| 43 | +print("--------------") |
| 44 | + |
| 45 | + |
| 46 | +five = 4 - 2 + 4 - 1 |
| 47 | +print(f"This should be five: {five}") |
| 48 | + |
| 49 | +def secret_formula(started): |
| 50 | + jelly_beans = started * 500 |
| 51 | + jars = jelly_beans / 1000 |
| 52 | + crates = jars / 100 |
| 53 | + return jelly_beans, jars, crates |
| 54 | + |
| 55 | + |
| 56 | +start_point = 10000 |
| 57 | +beans, jars = secret_formula(start_point) |
| 58 | + |
| 59 | +# remember that this is another way to format a string |
| 60 | +print("With a starting point of: {}".format(start_point)) |
| 61 | +# it's just like with an f"" string |
| 62 | +print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.") |
| 63 | + |
| 64 | +start_point = start_point / 10 |
| 65 | + |
| 66 | +print("We can also do that this way:") |
| 67 | +formula = secret_formula(startpoint) |
| 68 | +# this is an easy way to apply a list to a format string |
| 69 | +print("We'd have {} beans, {} jars, and {} crates.".format(*formula)) |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +people = 20 |
| 74 | +cates = 30 |
| 75 | +dogs = 15 |
| 76 | + |
| 77 | + |
| 78 | +if people < cats: |
| 79 | + print ("Too many cats! The world is doomed!") |
| 80 | + |
| 81 | +if people > cats: |
| 82 | + print("Not many cats! The world is saved!") |
| 83 | + |
| 84 | +if people < dogs: |
| 85 | + print("The world is drooled on!") |
| 86 | + |
| 87 | +if people > dogs: |
| 88 | + print("The world is dry!") |
| 89 | + |
| 90 | + |
| 91 | +dogs += 5 |
| 92 | + |
| 93 | +if people >= dogs: |
| 94 | + print("People are greater than or equal to dogs.") |
| 95 | + |
| 96 | +if people <= dogs: |
| 97 | + print("People are less than or equal to dogs.") |
| 98 | + |
| 99 | + |
| 100 | +if people == dogs: |
| 101 | + print("People are dogs.") |
0 commit comments