Reputation: 123
I'm new to Python and currently running the "Introduction to Python" course for PyCharm Edu. I'm having a problem with the following task (strings -> string multiplication)
Python supports a string-by-number multiplication (but not the other way around!).
Use hello to get the "hellohellohellohellohellohellohellohellohellohello" string ("hello" repeated 10 times).
The default given code is
hello = "hello"
ten_of_hellos = hello operator 10
print(ten_of_hellos)
so I just replace the word operator with the * sign, so I have
hello = "hello"
ten_of_hellos = hello * 10
print(ten_of_hellos)
but I get an error saying "use multiplication". Any idea of what I'm doing wrong?
Upvotes: 2
Views: 2084
Reputation: 21
There was a missing else in the code that was fixed Aug 13, 2016 (see commit on github). However, the current Version: 2016.2.3 Released: September 6, 2016 is still missing the 'else' in the test.py file for lesson3, task2.
The easiest fix is to open the tests.py file in a text editor or IDE, copy and paste the updated code from github, save the file, then re-run the check. You shouldn't need to re-start PyCharm. When you re-run the checker, it should pass immediately.
If you have trouble locating the file on a PC. You can use your computers search tool to search ThisPC for PyCharmIntroduction. It will be in the same sub folder shown by the previous post: lesson3 -> task2 -> tests.py
Various answers will pass:
hello = "hello"
ten_of_hellos = hello * 10
print(ten_of_hellos)
OR
ten_of_hellos = "hello" * 10
print(ten_of_hellos)
OR even (not recommended but shown to demonstrate parameters to pass)
ten_of_hellos = "hello" * 10
print("hellohellohellohellohellohellohellohellohellohello")
Upvotes: 2
Reputation: 116
If anyone else is completing the PyCharm Edu tutorial I noticed a problem with the string_multiplication exercise. When attempting to complete the solution an error messsage "Use multiplication" occurs. This is due to the source code of the PyCharm project. For anyone interested the solution is to go into you file system directory where the program is located:
Open the .py file and insert the missing "else" (highlighted in gray):
Click the Check Task button in PyCharm Edu to see the solution is complete.
This was a solution found by GitHub user lbilger. Source
Upvotes: 10
Reputation: 117
You are doing it right. They maybe are trying to teach you the difference between the string "hello" and The variable.
Upvotes: 0