Python Forum
output correction using print() function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
output correction using print() function
#1
HI everyone , can you help me to solve this task please specially the first question for others

print(" *")
print(" * *")
print(" * *")
print(" * *")
print("*** ***")
print(" * *")
print(" * *")
print(" *****")

Try to:

minimize the number of print() function invocations by inserting the \n sequence into the strings
make the arrow twice as large (but keep the proportions)

duplicate the arrow, placing both arrows side by side; note: a string may be multiplied by using the following trick: "string" * 2 will produce "stringstring" (we'll tell you more about it soon)

remove any of the quotes, and look carefully at Python's response; pay attention to where Python sees an error - is this the place where the error really exists?

do the same with some of the parentheses;

change any of the print words into something else, differing only in case (e.g., Print) - what happens now?
replace some of the quotes with apostrophes; watch what happens carefully.
Reply
#2
As far as understand this, you would only need 1 print statement.
Either concatenate everything into 1 string mixed with the '\n' ,
or make a list of the words, and print in a for loop.
?
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu)
Reply
#3
(Aug-10-2020, 09:39 AM)afefDXCTN Wrote: HI everyone , can you help me to solve this task please specially the first question for others

print(" *")
print(" * *")
print(" * *")
print(" * *")
print("*** ***")
print(" * *")
print(" * *")
print(" *****")

Try to:

minimize the number of print() function invocations by inserting the \n sequence into the strings
make the arrow twice as large (but keep the proportions)

duplicate the arrow, placing both arrows side by side; note: a string may be multiplied by using the following trick: "string" * 2 will produce "stringstring" (we'll tell you more about it soon)

remove any of the quotes, and look carefully at Python's response; pay attention to where Python sees an error - is this the place where the error really exists?

do the same with some of the parentheses;

change any of the print words into something else, differing only in case (e.g., Print) - what happens now?
replace some of the quotes with apostrophes; watch what happens carefully.

Here are some of my answers, I am sure there are better ones, but they do the trick.
#Original
print("    *")
print("   * *")
print("  *   *")
print(" *     *")
print("***   ***")
print("  *   *")
print("  *   *")
print("  *****")

#Minimizing the number of print invocations
print("    *\n   * *\n  *   *\n *     *\n***   ***\n  *   *\n  *   *\n  *****")


#Making the arrow twice as large (Keeping the proportions)
print("     *       ")            #<-- Had to add spaces before to correct distortion
print("    * *      ")            #<-- Had to add this line to correct distortion
print("   *"," *    ",sep=2*" ")   #<-- Add as many spaces as necessary inside sep argument
print("  * ","  *   ",sep=2*" ")
print(" *  ","   *  ",sep=2*" ")
print("*** ","  *** ",sep=2*" ")
print("  * ","  *   ",sep=2*" ")
print("  * ","  *   ",sep=2*" ")
print("  **","***   ",sep=2*"*")   #<-- Add as many "*" as necessary inside sep argument


#Duplicating the arrow placing both side by side
print(2*"    *     ") #<-- Add spaces after, otherwise the duplication will distort the arrow
print(2*"   * *    ")
print(2*"  *   *   ")
print(2*" *     *  ")
print(2*"***   *** ")
print(2*"  *   *   ")
print(2*"  *   *   ")
print(2*"  *****   ")
The final questions are for you to get familiar to Python's error and warning messages. Big Grin Big Grin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print function output wrong with strings. mposwal 5 512 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Print output not working xninhox 7 864 Jan-16-2021, 09:42 AM
Last Post: xninhox
  Output with none, print(x) in function Vidar567 3 411 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  How to append to list a function output? rama27 5 849 Aug-24-2020, 10:53 AM
Last Post: DeaD_EyE
  print function help percentage and slash (multiple variables) leodavinci1990 3 659 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Invalid syntax on print function DoctorSmiles 2 992 Jul-12-2020, 07:39 PM
Last Post: DoctorSmiles
  Print output in single file using pramika loop deepakkhw 1 615 Jul-11-2020, 11:57 AM
Last Post: j.crater
  print output on Jenkins Pench 1 1,316 Jun-04-2020, 06:55 PM
Last Post: micseydel
  question about python3 print function jamie_01 5 919 May-25-2020, 09:58 AM
Last Post: pyzyx3qwerty
  output while using return instead of print muza 2 854 Apr-23-2020, 09:38 AM
Last Post: muza

Forum Jump:

User Panel Messages

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