Python Forum
i need assistance on the output of a particular code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need assistance on the output of a particular code
#1
def sentence(subject="i", predicate="play", object="football"):
    print(subject, predicate, object)

sentence()
Output:
('i', 'play', 'football')
please I just started coding a month ago I need an assistant on why this code I executed "i play football" displayed the comma's and apostrophes sign
Reply
#2
This particular code sample is pretty simple, but next time make sure to use Python code tags. You can find help here.

By default print will display whitespace delimited input arguments by default, if you don't provide different formatting rules/arguments. What is the desired outcome you want instead?
Reply
#3
[quote="j.crater" pid="47631" dateline="1526736673"]This particular code sample is pretty simple, but
I want the commas, apostrophes and Bracket removed.
Reply
#4
what you supply to print functions is in fact tuple. So it prints tuple
you must learn string formatting
def sentence(subject="i", predicate="play", object_="football"):
    print('{} {} {}'.format(subject, predicate, object_))
 
sentence()
or you can use join method
def sentence(subject="i", predicate="play", object_="football"):
    print(' '.join([subject, predicate, object_])
 
sentence()
in python 3.6+ you can use the new f-strings
def sentence(subject="i", predicate="play", object_="football"):
    print(f'{subject} {predicate} {object_}')
 
sentence()
finally, note that I replaced object with object_, because object is builtin and you are overshadowing it which will bring problems
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 300 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  I cannot able to see output of this code ted 1 715 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Code Assistance needed in saving the file MithunT 0 782 Oct-09-2022, 03:50 PM
Last Post: MithunT
  why I dont get any output from this code William369 2 1,084 Jun-23-2022, 09:18 PM
Last Post: William369
  How can I organize my code according to output that I want ilknurg 1 1,137 Mar-11-2022, 09:24 AM
Last Post: perfringo
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,165 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Why this code not getting desired output ? MDRI 2 2,485 Sep-18-2020, 02:11 AM
Last Post: MDRI
  I couldn't understand the output of the below code ravich129 1 1,892 Dec-12-2019, 06:24 AM
Last Post: sandeep_ganga
  Output of Python code hemal07yc 5 3,872 Sep-13-2019, 11:33 AM
Last Post: perfringo
  Output not following rules set in code. Escribblings 4 3,056 Apr-24-2019, 12:49 PM
Last Post: Escribblings

Forum Jump:

User Panel Messages

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