Python Forum
please help with this question about using operators to multiply a string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
please help with this question about using operators to multiply a string?
#1
mystery_string = "ABCDE"

#You may modify the lines of code above, but don't move them!
#When you Submit your code, we'll change these lines to
#assign different values to the variables.

#In the example above, we saw using operators to add
#characters to the end of a string, and using operators to
#multiply a string.
#
#Add some code below that uses those operators to modify
#mystery_string such that its value at the end of the
#program is: ABCDE.ABCDE.ABCDE.??? Then, print the final
#value of mystery_string.
#
#You should not create any new strings longer than one
#character. We'll test your code with a couple other
#variants on mystery_string, but in all cases the results
#should be the same: the string repeated three times with
#a period after each repetition and three question marks
#at the end.


#Add your code here!
print(("ABCDE." * 3) + "???")

#the above is what I put in.
#below is the answer i am getting and am confused as to why my code is wrong.
#[Executed at: Tue Feb 26 9:02:19 PST 2019]

We found a few things wrong with your code. The first one is shown below, and the rest can be found in full_results.txt in the dropdown in the top left:

We tested your code with mystery_string = "VWXYZ". We expected your code to print this:

VWXYZ.VWXYZ.VWXYZ.???

However, it printed this:

ABCDE.ABCDE.ABCDE.???
My result was correct as far as I can see, but am getting queries regarding other "variables"
Don't understand whats wrong with it. Or don't understand the question in the first place. Please help.
Reply
#2
The 'ABCDE' value is just an example. Your code needs to work on whatever is in mystery_string at the time the code runs, not just on 'ABCDE'. So how can you get the same answer using mystery_string, but not using 'ABCDE'?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thank you all for your replies.
I have tried the below:-
This is a section from the question instruction:-
"#Add some code below that uses those operators to modify
#mystery_string such that its value at the end of the
#program is: ABCDE.ABCDE.ABCDE.??? Then, print the final
#value of mystery_string.
#
#You should not create any new strings longer than one
#character. We'll test your code with a couple other
#variants on mystery_string, but in all cases the results
#should be the same: the string repeated three times with
#a period after each repetition and three question marks
#at the end."

Below is what I entered into the Python IDLE on my desktop and got the correct response:-

[b]mystery_string = "ABCDE"
mystery_string = input("please enter a variable:  ")
print((mystery_string+".")*3+"???")[/b]
please neter the variable: ABCDE
ABCDE.ABCDE.ABCDE.???

>>>

please neter the variable: VWXYZ
VWXYZ.VWXYZ.VWXYZ.???

>>>

I put the same into the test environment:-

[b]mystery_string = "ABCDE"
mystery_string = input("please enter a variable:  ")
print((mystery_string+".")*3+"???")[/b]
We tested your code with mystery_string = "VWXYZ". We expected your code to print this:

VWXYZ.VWXYZ.VWXYZ.???

However, it printed this:

EOFError: EOF when reading a line



We tested your code with mystery_string = "ZSYNP". We expected your code to print this:

ZSYNP.ZSYNP.ZSYNP.???

However, it printed this:

EOFError: EOF when reading a line
Reply
#4
I assume you are not including the b tags when you put it in the test environment. It runs fine on my machine. How exactly are you putting it in the test environment? If you copy and paste it, it might be possible you missed the last parenthesis. That would cause the error you are seeing.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of if - and operators Pedro_Castillo 1 490 Oct-24-2023, 08:33 AM
Last Post: deanhystad
  String to List question help James_Thomas 6 982 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  syntax error question - string mgallotti 5 1,315 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Mixing Boolean and comparison operators Mark17 3 1,413 Jul-11-2022, 02:20 AM
Last Post: perfringo
Big Grin General programming question (input string)[ jamie_01 2 1,597 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 2,528 May-24-2021, 08:48 AM
Last Post: bowlofred
  Question on HTML formatting with set string in message Cknutson575 3 3,486 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  Magic Method Arithmetic Operators ClownPrinceOfCrime 3 2,320 Jan-10-2021, 03:24 PM
Last Post: ndc85430
  Class and Operators in Python rsherry8 1 1,995 May-27-2020, 07:09 PM
Last Post: buran
  question: finding multiple strings within string djf123 4 2,972 May-16-2020, 01:00 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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