# -*- coding: utf-8 -*-
"""
fill-in-the-blanks1.py
"""
# -*- coding: utf-8 -*-
"""
p1
"""
level1 = '''The __1__ command can print out any types of a variable. __2__ defines a function that could be
called out at any place in the document. A __3__ is a group of strings, variables or numbers. __3__ can also be
printed by the __1__ command. __4__ is the statement of true or false.'''
level2 = '''A ___1___ is created with the def keyword. You specify the inputs a ___1___ takes by
adding ___2___ separated by commas between the parentheses. ___1___ by default return ___3___ if you
don't specify the value to return. ___2___ can be standard data types such as string, number, dictionary,
tuple, and ___4___ or can be more complicated such as objects and lambda functions.'''
level3 = '''__1__ , __2__ , __3__ , all belongs to the if statement. __1__ will be used at the beginning of the
if statement, __2__ will be used in the middle between the __4__ and the __5__ statement. '''
variables1 = ["print", "def", "list", "boolean"]
variables2 = ["function", "parameter", "false", "list"]
variables3 = ["if", "elif", "else", "first"]
d = "__1__"
e = "__2__"
f = "__3__"
g = "__4__"
h = "__5__"
def replacevar(string, variable, inputa, finish):
string.split()
while True:
if inputa == variable[0]:
string = string.replace(d, inputa)
finish = ""
finish = finish.join(string)
return finish
break;
else:
print ("Your Answer is incorrect, pls try again")
return True
level = input("Which level do you want to play? (1, 2 or 3)")
if level == "1":
print (level1)
useranswer = input("Please enter the value for variable NO.1: ")
replacevar(level1, variables1, useranswer, finish1)
print (finish1)
code Python ci-dessus, c'est juste la première partie du programme qui vous demande de remplir le vide et le remplacer ..... avec le mot que vous avez entré si votre la réponse est correcte. Mais quand j'ai lancé le programme, après avoir tapé 1, la question a montré comme prévu, mais après avoir tapé "print" (sans le "") pour la réponse pour la première variable "", il n'imprime pas le chaîne avec des mots remplacés.code ne marche pas imprimer ce
Il semble qu'il manque quelque chose, la variable 'finish1' n'est définie nulle part. – fjarri