Hỏi về lỗi trong Python

Em học python theo video của anh Đạt tới bài 20 thì gặp 1 lỗi rất khó chịu

Powershell hiện ra ở bên trái trong khi đúng phải là như bên phải

em code giống với book 100% nhưng vẫn không hiểu sao nó lại in ra thế này

2 Likes

Bạn cứ up code lên xem, chứ ko thì khó mà giúp lắm

1 Like

Mở file txt lên xem luôn…

1 Like

File txt đây ạ

1 Like

code thì lúc đầu e nghĩ e sai nên e vào cop nguyên đoạn code của sách vào luôn mà vẫn k đc

1 Like

tiến lẽ để người được hỏi đi tìm cái code à

1 Like
from sys import argv

script, input_file = argv

def print_all(f):
    print f.read()

def rewind(f):
    f.seek(0)

def print_a_line(line_count, f):
    print line_count, f.readline()

current_file = open(input_file)

print "First let's print the whole file:\n"

print_all(current_file)

print "Now let's rewind, kind of like a tape."

rewind(current_file)

print "Let's print three lines:"

current_line = 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

Code đây ạ :smile:

1 Like

Bạn dùng markdown để viết code ấy, như vậy khó nhìn lắm

3 Likes

e sửa lại rồi bác à :smile:

1 Like

Sửa lại thế này xem bạn:

for line in current_file:
     print line.strip()
1 Like

Bạn làm theo bạn này và post kết qủa lên xem

1 Like

Bác print theo kiểu raw xem nó ra cái gì :smile:

print ‘%r’ % text

1 Like

mình cop từ bài dạy vào luôn

1 Like

Tự đánh file text vào đi chứ code là không có sai rồi đó :v

Lúc đầu cũng tự thêm 3 chữ Huynh Thanh Quang vào nó out ra cũng bị vậy :cry:

Sau cop 3 chuỗi trong book vào file bị vậy

Bạn làm theo bạn này post kết qủa lên xem :slight_smile:

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?