Python:如果代码块中的代码块

时间:2018-04-25 02:34:11

标签: python

我最近参加了一个python课程,现在正试图通过练习来补充和扩展我的知识。

我正在编写一个程序,将各种数据属性输入到文件中。

我已经观察到了一些东西,那就是我有一个for循环,它允许我输入有关团队成员的各种属性,然后将其添加到文件中。但是,我发现代码没有阻止'因为我已经习惯了。我去检查上面的代码,当我尝试添加代码块上面 for block时,它会添加它。有谁知道你是否可以添加一个IF块到" for"块?如果没有,有人可以向我描述这样的语句的哪些属性违反了python的约定?

请查看以下代码以获取洞察力。这是我关于stackoverflow的第二个问题,所以我会尽力强调有问题的代码。

#This is a program that gets information about team members and
#returns whether or not they are any good.

def main():
    #Get the name of the user:
    user = str(input('What is your name user?: ')
    #Get the number of team members
    num_team = int(input('How many team member records ' + \
                         'do you want to create {}'.format(name)))

    team_name = str(input('what is the name of the team' + \
                          'that you are entering members for {}'.format(name)))
    team_name = team_name + '.txt'
    #we are now going to create a file that is name after the team
    #team that we are inputting team members for

    if offense_defense == "O":


    team_file = open(team_name,'w')

    #Get each team members data and write it to the file.
    for count in (1, num_team + 1):
               print('{} Enter data for team member #'.format(name), count, sep='')
               name = input('Name: ')
               offense_defense = input('Is {} a member of the Offense (O) or the Defense (D)')
               **if offense_defense == 'O':**


               passes = input('Enter the number of passes: ')
               dept = input(': ')

0 个答案:

没有答案