1. Homepage
  2. Programming
  3. [2022] COMP(2041|9044) 22T2 Software Construction — Week 06 Weekly Test Questions

[2022] COMP(2041|9044) 22T2 Software Construction — Week 06 Weekly Test Questions

Engage in a Conversation
COMP2041COMP9044Softeware ConstructionWeekly Test QuestionsUNSW

Week 06 Weekly Test Questions CourseNana.COM

  CourseNana.COM

Getting Started CourseNana.COM

Set up for the test by creating a new directory called test06 and changing to this directory. CourseNana.COM

1   $ mkdir test06 CourseNana.COM

2   $ cd test06 CourseNana.COM

There are no provided files for this test. CourseNana.COM

  CourseNana.COM

WEEKLY TEST QUESTION: CourseNana.COM

Create A File of Integers In Python CourseNana.COM

Write a Python program, CourseNana.COM

create_integers_file.py CourseNana.COM

which takes 3 arguments. CourseNana.COM

The first and second arguments will specify a range of integers. CourseNana.COM

The third argument will specify a filename. CourseNana.COM

Your program should create a file of this name containing the specified integers. CourseNana.COM

For example: CourseNana.COM

1   $ ./create_integers_file.py 40 42 fortytwo.txt CourseNana.COM

2   $ cat fortytwo.txt CourseNana.COM

3   40 CourseNana.COM

4   41 CourseNana.COM

5   42 CourseNana.COM

6   $ ./create_integers_file.py -5 5 a.txt CourseNana.COM

7   $ cat a.txt CourseNana.COM

8   -5 CourseNana.COM

9   -4 CourseNana.COM

10 -3 CourseNana.COM

11 -2 CourseNana.COM

12 -1 CourseNana.COM

13 0 CourseNana.COM

14 1 CourseNana.COM

15 2 CourseNana.COM

16 3 CourseNana.COM

17 4 CourseNana.COM

18 5 CourseNana.COM

19 $ ./create_integers_file.py 1 1000 a.txt CourseNana.COM

20 $ wc a.txt CourseNana.COM

21 1000 1000 3893 a.txt CourseNana.COM

NOTE: CourseNana.COM

You assume your program is give three valid arguments. CourseNana.COM

Your program can assume its first and second arguments will be integers. CourseNana.COM

Your program can assume its second argument is greater than or equal to its first argument. CourseNana.COM

Your answer must be Python only. You can not use other languages such as Shell, Perl or C. CourseNana.COM

Make the first line of your script #!/usr/bin/env python3 CourseNana.COM

You may not run external programs. For example, you can't run seq. CourseNana.COM

No error checking is necessary. CourseNana.COM

  CourseNana.COM

When you think your program is working you can autotest to run some simple automated tests: CourseNana.COM

1   $ 2041 autotest python_create_integers_file CourseNana.COM

When you are finished working on this exercise you must submit your work by running give: CourseNana.COM

1   $ give cs2041 test06_python_create_integers_file create_integers_file.py CourseNana.COM

  CourseNana.COM

WEEKLY TEST QUESTION: CourseNana.COM

Print the N-th Line of a File CourseNana.COM

Write a Python program, nth_line.py which prints the n-th line of a file. CourseNana.COM

It will be given two arguments n and the file name. CourseNana.COM

Your program should print nothing if the file does not have an n-th line CourseNana.COM

  CourseNana.COM

1   $ seq 42 99 > numbers.txt CourseNana.COM

2   $ head numbers.txt CourseNana.COM

3   42 CourseNana.COM

4   43 CourseNana.COM

5   44 CourseNana.COM

6   45 CourseNana.COM

7   46 CourseNana.COM

8   47 CourseNana.COM

9   48 CourseNana.COM

10 49 CourseNana.COM

11 50 CourseNana.COM

12 51 CourseNana.COM

13 $ tail numbers.txt CourseNana.COM

14 90 CourseNana.COM

15 91 CourseNana.COM

16 92 CourseNana.COM

17 93 CourseNana.COM

18 94 CourseNana.COM

19 95 CourseNana.COM

20 96 CourseNana.COM

21 97 CourseNana.COM

22 98 CourseNana.COM

23 99 CourseNana.COM

24 $ ./nth_line.py 1 numbers.txt CourseNana.COM

25 42 CourseNana.COM

26 $ ./nth_line.py 20 numbers.txt CourseNana.COM

27 61 CourseNana.COM

28 $ ./nth_line.py 1000 numbers.txt CourseNana.COM

29 $ echo this file has one line > file.txt CourseNana.COM

30 $ cat file.txt CourseNana.COM

31 this file has one line CourseNana.COM

32 $ ./nth_line.py 1 file.txt CourseNana.COM

33 this file has one line CourseNana.COM

34 $ ./nth_line.py 42 file.txt CourseNana.COM

  CourseNana.COM

NOTE: CourseNana.COM

You assume your program is give two valid arguments. CourseNana.COM

Your program can assume its first argument will be a positive integer. CourseNana.COM

You should not assume anything about the lines in the file. CourseNana.COM

You can assume the file contains ASCII text. CourseNana.COM

Your answer must be Python only. You can not use other languages such as Shell, Perl or C. CourseNana.COM

Make the first line of your script #!/usr/bin/env python3 CourseNana.COM

You may not run external programs. For example, you can't run sed. CourseNana.COM

No error checking is necessary. CourseNana.COM

  CourseNana.COM

When you think your program is working you can autotest to run some simple automated tests: CourseNana.COM

1   $ 2041 autotest python_nth_line CourseNana.COM

When you are finished working on this exercise you must submit your work by running give: CourseNana.COM

1   $ give cs2041 test06_python_nth_line nth_line.py CourseNana.COM

  CourseNana.COM

WEEKLY TEST QUESTION: CourseNana.COM

Reverse the Lines of a File into a New File CourseNana.COM

  CourseNana.COM

Write a Python program, reverse_file.py which creates a file that is the reverse of another files. CourseNana.COM

It will be given two arguments the file name of the source file, and the file name of the destination file. CourseNana.COM

Your program should print nothing. CourseNana.COM

  CourseNana.COM

1   $ seq 42 99 > numbers.txt CourseNana.COM

2   $ head numbers.txt CourseNana.COM

3   42 CourseNana.COM

4   43 CourseNana.COM

5   44 CourseNana.COM

6   45 CourseNana.COM

7   46 CourseNana.COM

8   47 CourseNana.COM

9   48 CourseNana.COM

10 49 CourseNana.COM

11 50 CourseNana.COM

12 51 CourseNana.COM

13 $ tail numbers.txt CourseNana.COM

14 90 CourseNana.COM

15 91 CourseNana.COM

16 92 CourseNana.COM

17 93 CourseNana.COM

18 94 CourseNana.COM

19 95 CourseNana.COM

20 96 CourseNana.COM

21 97 CourseNana.COM

22 98 CourseNana.COM

23 99 CourseNana.COM

24 $ ./reverse_file.py numbers.txt new_numbers.txt CourseNana.COM

25 $ head new_numbers.txt CourseNana.COM

26 99 CourseNana.COM

27 98 CourseNana.COM

28 97 CourseNana.COM

29 96 CourseNana.COM

30 95 CourseNana.COM

31 94 CourseNana.COM

32 93 CourseNana.COM

33 92 CourseNana.COM

34 91 CourseNana.COM

35 90 CourseNana.COM

36 $ tail new_numbers.txt CourseNana.COM

37 51 CourseNana.COM

38 50 CourseNana.COM

39 49 CourseNana.COM

40 48 CourseNana.COM

41 47 CourseNana.COM

42 46 CourseNana.COM

43 45 CourseNana.COM

44 44 CourseNana.COM

45 43 CourseNana.COM

46 42 CourseNana.COM

47 $ echo this file has one line > file.txt CourseNana.COM

48 $ cat file.txt CourseNana.COM

49 this file has one line CourseNana.COM

50 $ ./reverse_file.py file.txt reverse.txt CourseNana.COM

51 $ cat reverse.txt CourseNana.COM

52 this file has one line CourseNana.COM

  CourseNana.COM

  CourseNana.COM

When you think your program is working you can autotest to run some simple automated tests: CourseNana.COM

1   $ 2041 autotest python_reverse_file CourseNana.COM

When you are finished working on this exercise you must submit your work by running give: CourseNana.COM

1   $ give cs2041 test06_python_reverse_file reverse_file.py CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
COMP2041代写,COMP9044代写,Softeware Construction代写,Weekly Test Questions代写,UNSW代写,COMP2041代编,COMP9044代编,Softeware Construction代编,Weekly Test Questions代编,UNSW代编,COMP2041代考,COMP9044代考,Softeware Construction代考,Weekly Test Questions代考,UNSW代考,COMP2041help,COMP9044help,Softeware Constructionhelp,Weekly Test Questionshelp,UNSWhelp,COMP2041作业代写,COMP9044作业代写,Softeware Construction作业代写,Weekly Test Questions作业代写,UNSW作业代写,COMP2041编程代写,COMP9044编程代写,Softeware Construction编程代写,Weekly Test Questions编程代写,UNSW编程代写,COMP2041programming help,COMP9044programming help,Softeware Constructionprogramming help,Weekly Test Questionsprogramming help,UNSWprogramming help,COMP2041assignment help,COMP9044assignment help,Softeware Constructionassignment help,Weekly Test Questionsassignment help,UNSWassignment help,COMP2041solution,COMP9044solution,Softeware Constructionsolution,Weekly Test Questionssolution,UNSWsolution,