diff --git "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.json" "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.json" index 0b509838db2b8956ab530bbcc8b22ab864b740a0..d73bb045f3004f0d3876838a595c3c8fe92b447a 100644 --- "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.json" +++ "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.json" @@ -1,19 +1,5 @@ { - "one_line": { - "token[\"key\"] ": [ - "token" - ], - "print(\"\".join(result))": [ - "print(result)" - ], - "for token in tokens": [ - "for t in tokens" - ], - "result = []": [ - "result = {}" - ] - }, - "source": "process.py", + "source": "process.md", "depends": [], "exercise_id": 27, "type": "code_options" diff --git "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.md" "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.md" new file mode 100644 index 0000000000000000000000000000000000000000..34e778df018d7d34e215fc44d979bcfff87ad8ae --- /dev/null +++ "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.md" @@ -0,0 +1,98 @@ +# 编程语言简史 + +历史上有很多编程语言,他们在编程语言发展的过程中都起到过重要的作用。 + +下面的 Python 数组包含了历史上的大部分编程语言。 + +```python +languages = ["Regional Assembly Language","Autocode","FORTRAN","IPL (LISP的先驱)","FLOW-MATIC (COBOL的先驱)","COMTRAN (COBOL的先驱)","LISP","ALGOL 58","FACT (COBOL的先驱)","COBOL","APL","Simula","SNOBOL","CPL (C的先驱)","BASIC","PL/I","BCPL (C的先驱)","Logo","Pascal","Forth","C语言","Smalltalk","Prolog","ML","Scheme","SQL","Ada","C++","Common Lisp","MATLAB","Eiffel","Objective-C","Erlang","Perl","Tcl","FL (Backus)","Haskell","Python","Visual Basic","HTML","Ruby","Lua","CLOS (part of ANSI Common Lisp)","Java","Delphi (Object Pascal)","JavaScript","PHP","REBOL","D","C#","Visual Basic .NET","F#","Scala","Factor","Windows PowerShell","Rust","Clojure","Go"] +``` + +下面的 Python 数组包含了这些编程对应的创建时间。 + +```python +years = [1951, 1952, 1954, 1954, 1955, 1957, 1958, 1958, 1959, 1959, 1962, 1962, 1962, 1963, 1964, 1964, 1967 ,1968 ,1970 ,1970 ,1972 ,1972 ,1972 ,1973 ,1975 ,1978 ,1980 ,1983 ,1984 ,1984 ,1985 ,1986 ,1986 ,1987 ,1988 ,1989 ,1990 ,1991 ,1991 ,1991 ,1993 ,1993 ,1994 ,1995 ,1995 ,1995 ,1995 ,1997 ,1999 ,2001 ,2001 ,2002 ,2003 ,2003 ,2006 ,2006 ,2007 ,2009] +``` + +编写一个 Python 程序,每行打印每个编程语言的名字和对应的创建时间,例如: + +```python +Regional Assembly Language : 1951 +Autocode : 1952 +FORTRAN : 1954 +... +``` + +请找出以下代码中错误的选项。 + + +## template + +```python +if __name__ == '__main__': + languages = ["Regional Assembly Language","Autocode","FORTRAN","IPL (LISP的先驱)","FLOW-MATIC (COBOL的先驱)","COMTRAN (COBOL的先驱)","LISP","ALGOL 58","FACT (COBOL的先驱)","COBOL","APL","Simula","SNOBOL","CPL (C的先驱)","BASIC","PL/I","BCPL (C的先驱)","Logo","Pascal","Forth","C语言","Smalltalk","Prolog","ML","Scheme","SQL","Ada","C++","Common Lisp","MATLAB","Eiffel","Objective-C","Erlang","Perl","Tcl","FL (Backus)","Haskell","Python","Visual Basic","HTML","Ruby","Lua","CLOS (part of ANSI Common Lisp)","Java","Delphi (Object Pascal)","JavaScript","PHP","REBOL","D","C#","Visual Basic .NET","F#","Scala","Factor","Windows PowerShell","Rust","Clojure","Go"] + + years = [1951, 1952, 1954, 1954, 1955, 1957, 1958, 1958, 1959, 1959, 1962, 1962, 1962, 1963, 1964, 1964, 1967 ,1968 ,1970 ,1970 ,1972 ,1972 ,1972 ,1973 ,1975 ,1978 ,1980 ,1983 ,1984 ,1984 ,1985 ,1986 ,1986 ,1987 ,1988 ,1989 ,1990 ,1991 ,1991 ,1991 ,1993 ,1993 ,1994 ,1995 ,1995 ,1995 ,1995 ,1997 ,1999 ,2001 ,2001 ,2002 ,2003 ,2003 ,2006 ,2006 ,2007 ,2009] + + for i in range(0, len(languages)): + language = languages[i] + year = years[i] + print(language, ':', year) + + i = 0 + while i < len(years): + language = languages[i] + year = years[i] + print(language, ':', year) + i += 1 + + [print(languages[i], ':', years[i]) for i in range(0, len(languages))] +``` + +## 答案 + +```python +if __name__ == '__main__': + languages = ... + years = ... + for language in languages: + for year in years: + print(language, ':', year) +``` + +## 选项 + +### for循环打印 + +```python +if __name__ == '__main__': + languages = ... + years = ... + for i in range(0, len(languages)): + language = languages[i] + year = years[i] + print(language, ':', year) +``` + +### while循环打印 + +```python +if __name__ == '__main__': + languages = ... + years = ... + i = 0 + while i < len(years): + language = languages[i] + year = years[i] + print(language, ':', year) + i += 1 +``` + +### 列表表达式打印 + +```python +if __name__ == '__main__': + languages = ... + years = ... + [print(languages[i], ':', years[i]) for i in range(0, len(languages))] +``` diff --git "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.py" "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.py" index bdb55d7b0bb68d47f70c5d10715de649fa5d34b1..9cd2edbfcb7f10e87c131bb8d9033e3f40713d8a 100644 --- "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.py" +++ "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/2.\347\250\213\345\272\217\350\256\276\350\256\241\346\200\235\346\203\263/process.py" @@ -1,21 +1,25 @@ # -*- coding: UTF-8 -*- # 作者:幻灰龙 -# 标题:基本的 Python 处理 -# 描述:Python 过程性代码,用循环合并“猴子在苹果树下打架”文本并打印 +# 标题:编程语言简史 +# 描述:循环打印每一个编程语言的创建年份 if __name__ == '__main__': - tokens = [ - { - "key": "猴子在" - }, - { - "key": "苹果树下" - }, - { - "key": "打架" - } - ] - result = [] - for token in tokens: - result.append(token["key"]) - print("".join(result)) + languages = ["Regional Assembly Language", "Autocode", "FORTRAN", "IPL (LISP的先驱)", "FLOW-MATIC (COBOL的先驱)", "COMTRAN (COBOL的先驱)", "LISP", "ALGOL 58", "FACT (COBOL的先驱)", "COBOL", "APL", "Simula", "SNOBOL", "CPL (C的先驱)", "BASIC", "PL/I", "BCPL (C的先驱)", "Logo", "Pascal", "Forth", "C语言", "Smalltalk", "Prolog", "ML", "Scheme", "SQL", "Ada", "C++", "Common Lisp", + "MATLAB", "Eiffel", "Objective-C", "Erlang", "Perl", "Tcl", "FL (Backus)", "Haskell", "Python", "Visual Basic", "HTML", "Ruby", "Lua", "CLOS (part of ANSI Common Lisp)", "Java", "Delphi (Object Pascal)", "JavaScript", "PHP", "REBOL", "D", "C#", "Visual Basic .NET", "F#", "Scala", "Factor", "Windows PowerShell", "Rust", "Clojure", "Go"] + + years = [1951, 1952, 1954, 1954, 1955, 1957, 1958, 1958, 1959, 1959, 1962, 1962, 1962, 1963, 1964, 1964, 1967, 1968, 1970, 1970, 1972, 1972, 1972, 1973, 1975, 1978, 1980, 1983, + 1984, 1984, 1985, 1986, 1986, 1987, 1988, 1989, 1990, 1991, 1991, 1991, 1993, 1993, 1994, 1995, 1995, 1995, 1995, 1997, 1999, 2001, 2001, 2002, 2003, 2003, 2006, 2006, 2007, 2009] + + for i in range(0, len(languages)): + language = languages[i] + year = years[i] + print(language, ':', year) + + i = 0 + while i < len(years): + language = languages[i] + year = years[i] + print(language, ':', year) + i += 1 + + [print(languages[i], ':', years[i]) for i in range(0, len(languages))]