Hi All,
I’ve run into a bit of a problem with Ex26 (enjoying it a lot, by the way).
I have worked through the code and corrected as many errors as I could see, then started running it in Powershell. It runs up to the point between lines 10-23, and this is where my problem lies. When the code reaches this point, I get an error relating to line 11:
Traceback (most recent call last):
File “ex26.py”, line 11, in
script, filename = argv
ValueError: not enough values to unpack (expected 2, got 1)
So, I understand that the program is looking for two values, but only getting one (filename?). Am I right in thinking that there should be another line defining script?
Any help would be greatly appreciated. Code is appended below. Thanks in advance,
Dave
print("How old are you?", end=' ')
age = input()
print("How tall are you?", end=' ')
height = input() #missing height input line - fixed
print("How much do you weigh?", end=' ') #think this is missing a ")" - fixed
weight = input()
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
from sys import argv #added this line
script, filename = argv
txt = open(filename) #misspelled filename here - fixed
print("Here's your file {filename}:")
print(txt.read()) #misspelled txt - fixed
print("Type the filename again:")
file_again = input("> ")
txt_again = open(file_again)
print(txt_again_read()) #I think there is something wrong with this, but not sure.
print("Let's practice everything.")
print('You\'d need to know \'bout escapes with \\ that do: \n newlines and \t tabs.') #don't spread this over two lines
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
print("--------------") #missing " before ) - fixed
print(poem)
print("--------------") #missing " after ( - fixed
five = 10 - 2 + 3 - 6 #missing figure here, or additional arithmetic operator - fixed
print(f"This should be five: {five}") #missing close bracket - fixed
def secret_formula(started): #missing : after (started) - fixed
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100 #missing divided symbol - fixed
return jelly_beans, jars, crates
start_point = 10000
beans, jars, crates = secret_formula(start_point) #missing crates - fixed
# remember that this is another way to format a string
print("With a starting point of: {}".format(start_point))
# it's just like with an f"" string
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(start_point) #missing underscore between start and point in brackets - fixed
# 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
cats = 30 #variable cats misspelled - fixed
dogs = 15
if people < cats:
print ("Too many cats! The world is doomed!") #missing brackets around phrase to be printed - fixed.
if people < cats:
print("Not many cats! The world is saved!")
if people < dogs:
print("The world is drooled on!")
if people > dogs: #missing : after dogs - fixed
print("The world is dry!")
dogs += 5
if people >= dogs:
print("People are greater than or equal to dogs.")
if people <= dogs: #missing : after dogs - fixed
print("People are less than or equal to dogs.") #missing " after dogs.
if people == dogs: # = should be == - fixed
print("People are dogs.")