#HOW TF DO I DO THIS?

12 messages · Page 1 of 1 (latest)

elfin zenithBOT
#

@bitter pond

File Attachments Not Allowed

For safety reasons we do not allow files with certain file extensions.

power1301 Said

The Python program below converts a contact list to printing labels.

Ch6 homework starter.pyDownload Ch6 homework starter.pyOpen this document with ReadSpeaker docReader
The starting contact list: contact_list.txtDownload contact_list.txtOpen this document with ReadSpeaker docReader
Please run the program to see how the label file is created.

You must modify this program to:

  1. Add the Country, Phone number and the email to every entry of the the contact list - insert in file following the ZIP.
  2. Include the country, email and phone number in a separate lines of the label
  3. Use try/except to catch file operations errors.
  4. Extra credit: make printing of email and phone number on label optional (require user input).

Items 1,2,3 - 5 points each
Item 4 - 5 points

Submission: Runnable Python code, screen shot of execution, output file. I DONT UNDERSTAND WHAT IM DOING WRONG

Code Formatting

You can share your code using triple backticks like this:
```
YOUR CODE
```

Large Portions of Code

For longer scripts use Hastebin or GitHub Gists and share the link here

Ignored these files due to them having disallowed file extensions
  • Ch6_homework_starter.py
  • contact_list.txt
inland blade
#

Do you need help or want someone to do the work for you?

bitter pond
#

help because i need to learn but im not understanding shit

#

@inland blade it keeps telling me my list is out of range

#

I dont know whats going on

elfin zenithBOT
#

@bitter pond

File Attachments Not Allowed

For safety reasons we do not allow files with certain file extensions.

Code Formatting

You can share your code using triple backticks like this:
```
YOUR CODE
```

Large Portions of Code

For longer scripts use Hastebin or GitHub Gists and share the link here

Ignored these files due to them having disallowed file extensions
  • Ch6_homework_starter.py
bitter pond
#

i cant attach

#

def write_label(outfile, mylist):
# Construindo as linhas de cada label
label_line1 = f"{mylist[0]} {mylist[1]} {mylist[2]}"
label_line2 = mylist[3]
label_line3 = f"{mylist[4]} {mylist[5]} {mylist[6]}"

# Escrevendo no arquivo de saída
outfile.write(label_line1 + '\n')
outfile.write(label_line2 + '\n')
outfile.write(label_line3 + '\n')

# Escrevendo campos adicionais, se existirem
additional_fields = mylist[7:]  # Captura country, phone, email
for field in additional_fields:
    outfile.write(field + '\n')
    
outfile.write('\n')  # Linha em branco entre os labels

def read_contact(infile):
mylist = []

# Lendo os primeiros 3 campos: título, primeiro nome e sobrenome
for _ in range(3):
    line = infile.readline().strip()
    if not line:
        return None  # Retorna None se chegar ao fim do arquivo
    mylist.append(line)

# Lendo o endereço
mylist.append(infile.readline().strip())

# Lendo cidade, estado e CEP
for _ in range(3):
    line = infile.readline().strip()
    mylist.append(line)

# Lendo campos adicionais: country, phone, email
for _ in range(3):
    line = infile.readline().strip()
    mylist.append(line)

return mylist  # Retorna a lista completa com os dados do contato

def main():
# Contador de labels gerados
label_count = 0

# Abrindo os arquivos de entrada e saída
with open('contact_list.txt', 'r') as infile, open('labels.txt', 'w+') as outfile:
    while True:
        contact_data = read_contact(infile)
        if contact_data is None:  # Fim do arquivo
            break
        write_label(outfile, contact_data)
        label_count += 1

print("Wrote", label_count, "labels")

main()

inland blade
#

!format

elfin zenithBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```py
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB