Python Forum
print function output wrong with strings.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print function output wrong with strings.
#4
Indentation in Python does the job of {} in C. It is how you block code.

When I try to run your program I get an error.
f = open(r"C:\Users\emanpos\bbuser.txt","r")
for x in f:
print("<Number>")
print("      %s%s%s" %("<Number>", x,"</Number>"))
print('</Number>')
Error:
File "..., line 3 print("<Number>") ^ IndentationError: expected an indented block
I don't know why you aren't getting the same error. But as snippsat says, your program is not going to work the way you want because your code blocks are not properly indented
f = open(r"C:\Users\emanpos\bbuser.txt","r")
for x in f:
    print("<Number>")
    print("      %s%s%s" %("<Number>", x,"</Number>"))
    print('</Number>')
I don't care if you use f'strings or a context manager.
mposwal likes this post
Reply


Messages In This Thread
RE: print function output wrong with strings. - by deanhystad - Feb-11-2021, 03:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 323 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  problem in output of a function akbarza 9 1,242 Sep-29-2023, 11:13 AM
Last Post: snippsat
  Trying to understand strings and lists of strings Konstantin23 2 800 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,592 Mar-27-2023, 07:38 AM
Last Post: buran
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 944 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,126 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  How to print variables in function? samuelbachorik 3 928 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  How to output one value per request of the CSV and print it in another func? Student44 3 1,368 Nov-11-2022, 10:45 PM
Last Post: snippsat
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,619 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  How to print the output of a defined function bshoushtarian 4 1,337 Sep-08-2022, 01:44 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020