| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12409 | Python2020_MOOCS_Practice_Problem1 |
|
| 12710 | Python2020_MOOCS_Practice_Problem2 |
|
| 12713 | Python2020_MOOCS_Practice_Problem3 |
|
Description
Write a program that prompts the user to input two strings and reports the two strings' lengths, by reporting the shorter string first. But if they are of the same length then keep them in the original order. For example, (blue text = typed input, green highlight = program printout)
$ python3 compstr.py
Enter a string:
Great
Enter another string:
job
Shorter string: job (length 3)
Longer string: Great (length 5)
$ python3 compstr.py
Enter a string:
Mary
Enter another string:
lamb
First string: Mary (length 4)
Second string: lamb (length 4)
$
Note that in case the strings are of different lengths, the program says Shorter and Longer, but in case the strings are of equal length, the program says First and Second. You don't actually print in color… the letters are colored for illustration purpose only.
[HINT] Your program should start with these two lines:
s1 = input('Enter a string:\n')
s2 = input('Enter another string:\n')
Input
typed input (blue text)
Output
program printout (green highlight)
Sample Input Download
Sample Output Download
Discuss
Description
Write a Python program that takes two names from the inputs and prints two sentenses "XXX and OOO are my friends." and "OOO is my best friend" to the output, where "XXX" and "OOO" are the names from the inputs.
Assume the program is written in a file named "friends.py" and run from the command line. The following block shows how the terminal shall look like: (the text in pink is typed by the user; others are printed by the program)
$ python3 friends.py
Mary Cindy
Mary and Cindy are my friends.
Cindy is my best friend.
$
[Hint]
There is a space between "Mary" and "Cindy". Actually you might get "Mary Cindy" by calling input() just once. You should then use another method to separate the two names.
Watch out for spaces and new line characters -- any difference makes your code not accepted by Online Judge.
In this problem, one extra empty line is required after the both output sentence, "Mary and Cindy are my friends." and "Cindy is my best friend.".
Input
One sentence includes two names and one space between the names.
Output
Two sentences claiming your friends and your best friend with one extra empty line after each of the sentences.
Sample Input Download
Sample Output Download
Discuss
Description
This problem is the same as the previous one (Python2020_Self-Check4_Problem2), except for some minor changes in the output for you to understand some tricky things.
$ python3 friends.py
Mary Cindy
Mary and Cindy are my friends.
Cindy is my best friend.$
[Hint]
There is a space after "Mary and Cindy are my friends.". Select(反白) the text to see the hidden space. We won't be so tricky in the quizzes, but it's good for you to know what to be careful of.
There is no new line character after "Cindy is my best friend.". The dollar sign ($) is the prompt, not part of the program output.
You can refer to 7:47 in the 3rd lecture video of week 3 for how to omit the new line character when printing.
Please check out the description and sample output of the previous two problems and this one. What's the difference among "an new line character after the last line"(the usual case), "one extra new line after the last line", and "no new line character after the last line"?
If you are using Cygwin or other terminal, you'll see the differences among the three cases. If you are using Jupyter Notebook, you'll find out that the first case and the third case look like the same. Therefore, be very careful for new line characters if you want to use Jupyter Notebook for the quizzes.
Input
One sentence includes two names and one space between the names.
Output
Two sentences claiming your friends and your best friend with no new line character after the the last sentence.