Exercise 26 lp2thw - Corrected all errors. Script compiles and runs no issues

This commit is contained in:
Ganome 2021-04-20 00:14:25 +00:00
parent f82c3fa359
commit e51066f7be

View File

@ -1,29 +1,32 @@
import sys
print("How old are you?", end=' ') print("How old are you?", end=' ')
age = input() age = input()
print("How tall are you?", end=' ') print("How tall are you?", end=' ')
print("How much do you weigh?", end=' ' height = input()
print("How much do you weigh?", end=' ')
weight = input() weight = input()
print(f"So, you're {age} old, {height} tall and {weight} heavy.") 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("Here's your file {filename}:")
print(tx.read()) print(txt.read())
print("Type the filename again:") print("Type the filename again:")
file_again = input("> ") 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('Let\'s practice everything.')
print('You\'d need to know \'bout escapes print('You\'d need to know \'bout escapes')
with \\ that do \n newlines and \t tabs.') print('with \\ that do \n newlines and \t tabs.')
poem = """ poem = """
\tThe lovely world \tThe lovely world
@ -34,23 +37,23 @@ and requires an explanation
\n\t\twhere there is none. \n\t\twhere there is none.
""" """
print("--------------) print("--------------")
print(poem) print(poem)
print(--------------") print("--------------")
five = 10 - 2 + 3 - five = 10 - 2 + 3 - 6
print(f"This should be five: {five}" print(f"This should be five: {five}")
def secret_formula(started) def secret_formula(started):
jelly_beans = started * 500 jelly_beans = started * 500
jars = jelly_beans / 1000 jars = jelly_beans / 1000
crates = jars 100 crates = jars / 100
return jelly_beans, jars, crates return jelly_beans, jars, crates
start_point = 10000 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 # remember that this is another way to format a string
print("With a starting point of: {}".format(start_point)) 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 start_point = start_point / 10
print("We can also do that this way:") 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 # this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, and {} crates.".format(*formula)) print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
people = 20 people = 20
cates = 30 cats = 30
dogs = 15 dogs = 15
if people < cats: if people < cats:
print "Too many cats! The world is doomed!" print("Too many cats! The world is doomed!")
if people < cats: if people < cats:
print("Not many cats! The world is saved!") print("Not many cats! The world is saved!")
@ -80,7 +83,7 @@ if people < cats:
if people < dogs: if people < dogs:
print("The world is drooled on!") print("The world is drooled on!")
if people > dogs if people > dogs:
print("The world is dry!") print("The world is dry!")
@ -89,10 +92,10 @@ dogs += 5
if people >= dogs: if people >= dogs:
print("People are greater than or equal to dogs.") print("People are greater than or equal to dogs.")
if people <= dogs if people <= dogs:
print("People are less than or equal to dogs.) print("People are less than or equal to dogs.")
if people = dogs: if people == dogs:
print("People are dogs.") print("People are dogs.")