Python Forum
Am I wrong or is Udemy wrong? String Slicing!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Am I wrong or is Udemy wrong? String Slicing!
#4
(Nov-05-2022, 01:32 AM)rob101 Wrote: Maybe the answer is simply 'tinker'[1:4] ?

(Nov-05-2022, 05:54 AM)ndc85430 Wrote: Given the response you get, rob101's solution is sensible.

Why are you printing?

Do you know what an expression is? "tinker"[1:4] is an expression that evaluates to "ink". A function call is also an expression and it evaluates to the return value of the call. The print function's job is to write it's arguments to the console, not to produce a value to be used in the program (for example in a comparison used for the test case you have). Therefore, print returns None.

To add some more colour to the story: when we write software in the real world, we generally don't print things to check it's working correctly. The reason why not is humans: we're error prone! I could misread the output for example and say something's working when it isn't. Not only that but systems can be quite large, so this process would be time consuming and tedious. So what we do instead is get the computer to do the checking for us: we write test code that exercises the real code of the system to check it does the right thing. If something's not working right, these tests will fail and we can see a report of which ones have passed/failed along with what the failures were. Moreover, we can get computers to take action automatically based on whether the tests have passed or not. For the kinds of systems I work on (web apps, in my case APIs), this means either deploying the application if the tests pass or not deploying and alerting us if there was a failure.

In fact, you're seeing the benefits of this kind of automation when you're submitting your solution to Udemy. Imagine if you had to wait for someone to check your answers! One bad thing could be there might not be anyone online in your timezone so you would have to wait a while and not get the fast feedback that the website gives you.

Thanks for the thorough reply..much appreciated. That makes sense..as a beginner I'm used to regularly using print console..but can see 'return' is the key word.

Interestingly enough someone on Udemy did reply too...given there hadn't been a lot of action there in the comments...was quite amazing. They said the same thing as you all here...don't use print! Thanks!
Reply


Messages In This Thread
RE: Am I wrong or is Udemy wrong? String Slicing! - by Mavoz - Nov-05-2022, 11:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  wrong entries in sqlite database and tkinter epsilondatum 2 482 Apr-23-2024, 04:48 PM
Last Post: epsilondatum
  I don't know what is wrong (Python and SQL connection) shereen 3 478 Apr-01-2024, 08:56 AM
Last Post: Pedroski55
  Python3 string slicing Luchano55 4 724 Feb-17-2024, 09:40 AM
Last Post: Pedroski55
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 574 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Is this a multiprocessing bug in Python - or am I doing something wrong? haimat 1 1,296 Oct-18-2023, 06:07 AM
Last Post: absalom1
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 2,366 Aug-13-2023, 12:16 AM
Last Post: cubangt
  Wrong type error rowan_bradley 6 1,418 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,222 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  np.percentile returns wrong value? AceTylercholine 2 760 Jul-13-2023, 06:59 PM
Last Post: Skaperen
  Something wrong with my code FabianPruitt 5 945 Jul-03-2023, 10:55 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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