Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replace function
#4
Well, that's definitely not runnable example, but anyway.
The problem is that you have different number of undescores in the blanks and in the questions. They are different even between different elements in blanks:
e.g. ___1___ and __1__ (first is whit three, and in the question is with two)
__4__ (only two underscores)

and as a side note, in your case minimal runnable code snippet would be

blanks = ["___1___","___2___","___3___", "__4__"]
blanks_index = 0
quiz = '''Python is an __1__ oriented __2__ programming language that has become very popular. It was created by __3__ Van Rossum.Python has been used widely, especially for __4__ learning.'''
replaced_quiz = quiz.replace(blanks[blanks_index], 'object'.upper()) #This should replace the blanks with the user-answer, why is is not working??? :(
print replaced_quiz
Output:
Python is an __1__ oriented __2__ programming language that has become very popu lar. It was created by __3__ Van Rossum.Python has been used widely, especially for __4__ learning.
Reply


Messages In This Thread
Replace function - by LucasLambert - Mar-29-2017, 07:52 AM
RE: Replace function - by buran - Mar-29-2017, 08:07 AM
RE: Replace function - by LucasLambert - Mar-29-2017, 08:23 AM
RE: Replace function - by buran - Mar-29-2017, 08:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  basic random number generator in replace function krug123 2 2,068 Jul-31-2020, 01:02 PM
Last Post: deanhystad
  Beginner problem, replace function with for loop Motley_Cow 9 4,683 Sep-13-2019, 06:24 AM
Last Post: Motley_Cow
  Help trying to replace values in a function Rochense 1 2,317 Apr-01-2019, 09:59 PM
Last Post: nilamo
  Search & Replace - Newlines Added After Replace dj99 3 3,430 Jul-22-2018, 01:42 PM
Last Post: buran
  replace-function for selveral variables.. Specdrum 2 2,645 Jul-04-2018, 10:41 AM
Last Post: Specdrum
  Is there a built-in function to replace multiple bytes? Raptor88 4 34,288 Feb-25-2017, 03:48 AM
Last Post: Raptor88

Forum Jump:

User Panel Messages

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