Skip to content Skip to sidebar Skip to footer

Trying To Hammer Out This Zylabs Lab But Struggling

I've spent a couple of days on this Lab and I'm just struggling to get appropriate outputs. If someone can show me where to go with this, or if you have the code itself to share, I

Solution 1:

Hi I see you are learning Python. Everyone should know it, it's great!

Given that these are somewhat considered Python basics, I shall provide you with the resources to learn how to solve this yourself.

If you are given the answer then you won't learn this wonderful languageso let me ammend your labsheet with helpful links and instructions:


(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)

You need string user input. Look at the raw_input() function on this turorial site, don't forget to store the return value of the function.

(2) Report an error if the input string does not contain a comma.

You need to check if a string contains another string, check this SO answer and store it as a boolean (for this answer lets call it inputHasComma)

Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)

You will need a while loop, here is a tutorial on while loops, make the condition use inputHasComma (that you defined earlier).

(3) Using string splitting, extract the two words from the input string and then remove any spaces. Output the two words. (2 pts)

To split a string, here is a nice example. Store the result of the split into a variable (it should be a list) and then get the elements that you want out of the list like so:

values = ['A', 'B', 'C', 'D', 'E']
values[0] # returns 'A'
values[2] # returns 'C'

(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. (2 pts)

Do an if condition before you check for commas that uses a break (tutorial on break here). Look at the first example for an if condition that checks if a string equals another string on this tutorial site.


This should get you through the lab! Good luck. :)


Post a Comment for "Trying To Hammer Out This Zylabs Lab But Struggling"