From e51066f7be1464e7294a90672b510879c611b5c1 Mon Sep 17 00:00:00 2001 From: Ganome Date: Tue, 20 Apr 2021 00:14:25 +0000 Subject: [PATCH] Exercise 26 lp2thw - Corrected all errors. Script compiles and runs no issues --- python/lp3thw/Exercise26/ex26.py | 49 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/python/lp3thw/Exercise26/ex26.py b/python/lp3thw/Exercise26/ex26.py index d7aaa3a..1482340 100644 --- a/python/lp3thw/Exercise26/ex26.py +++ b/python/lp3thw/Exercise26/ex26.py @@ -1,29 +1,32 @@ +import sys + print("How old are you?", end=' ') age = input() print("How tall are you?", end=' ') -print("How much do you weigh?", end=' ' +height = input() +print("How much do you weigh?", end=' ') weight = input() print(f"So, you're {age} old, {height} tall and {weight} heavy.") -script, filename = argv +script, filename = sys.argv -txt = open(filenme) +txt = open(filename) print("Here's your file {filename}:") -print(tx.read()) +print(txt.read()) print("Type the filename again:") file_again = input("> ") -txt_again = open(file_again) +txt_again_read = open(file_again) -print(txt_again_read()) +print(txt_again_read) -print('Let's practice everything.') -print('You\'d need to know \'bout escapes - with \\ that do \n newlines and \t tabs.') +print('Let\'s practice everything.') +print('You\'d need to know \'bout escapes') +print('with \\ that do \n newlines and \t tabs.') poem = """ \tThe lovely world @@ -34,23 +37,23 @@ and requires an explanation \n\t\twhere there is none. """ -print("--------------) +print("--------------") print(poem) -print(--------------") +print("--------------") -five = 10 - 2 + 3 - -print(f"This should be five: {five}" +five = 10 - 2 + 3 - 6 +print(f"This should be five: {five}") -def secret_formula(started) +def secret_formula(started): jelly_beans = started * 500 jars = jelly_beans / 1000 - crates = jars 100 + crates = jars / 100 return jelly_beans, jars, crates start_point = 10000 -beans, jars = secret_formula(start_point) +beans, jars, crates = secret_formula(start_point) # remember that this is another way to format a string print("With a starting point of: {}".format(start_point)) @@ -60,19 +63,19 @@ print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.") start_point = start_point / 10 print("We can also do that this way:") -formula = secret_formula(startpoint) +formula = secret_formula(start_point) # this is an easy way to apply a list to a format string print("We'd have {} beans, {} jars, and {} crates.".format(*formula)) people = 20 -cates = 30 +cats = 30 dogs = 15 if people < cats: - print "Too many cats! The world is doomed!" + print("Too many cats! The world is doomed!") if people < cats: print("Not many cats! The world is saved!") @@ -80,7 +83,7 @@ if people < cats: if people < dogs: print("The world is drooled on!") -if people > dogs +if people > dogs: print("The world is dry!") @@ -89,10 +92,10 @@ dogs += 5 if people >= dogs: print("People are greater than or equal to dogs.") -if people <= dogs - print("People are less than or equal to dogs.) +if people <= dogs: + print("People are less than or equal to dogs.") -if people = dogs: +if people == dogs: print("People are dogs.")