# -*- 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)
Python代碼如上,這僅僅是要求您填寫的空白,替代節目的第一部分.....如果與你輸入的字你答案是正確的。但是當我運行該程序時,輸入1後,問題如預期般顯示,但是在輸入第一個變量「」的「print」(不帶「」)後,它不打印帶有替換詞的字符串。代碼犯規打印任何東西
似乎缺少某些東西,變量'finish1'沒有在任何地方定義。 – fjarri