cpsc111B-Asg1-Fall2023-Chiamaka Amanda Alumonah_10134234

.docx

School

Alexander College *

*We aren’t endorsed by this school

Course

111B

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

7

Uploaded by JudgeField13026

Report
CPSC111B - Introduction to Computation Fall 2023 Assignment #1 – Python Practice: working with functions & numbers Name and student #: __Chiamaka Amanda Alumonah_10134234 Name and student #: _nil_____________________________ ASSIGNMENT MARK: 41 / 50 Due Date: Wednesday, Oct. 4 th (11:59PM) Submission : Submit your assignment to the instructor through Canvas INBOX as one zipped file. For this Assignment, you will pair up with another student to complete it. As always, all your answers should use functions and every function should have a documentation string explaining the purpose of the function. Use the Python template given below at the top of your program you submit (don’t forget to modify it to include your information; your name, your student number, and purpose.) # Program: cpsc111B-F23-asg1.py # Author: Enter your Name and student number here # Class: CPSC 111 # Section: B # Date: 09/27/2023 # Task: Assignment #1 # Purpose: Describe here what assignment 1 is all about # which means what are you trying to solve in this # assignment. # Do not wait until the last minute to do this assignment in case you run into problems For programming questions, you may assume the user’s inputs are well- formatted. The questions are roughly ordered from the easiest to the hardest. This assignment has: 10 multiple choice questions, 2 marks each, 20 in total 2 essay questions, 3 marks each, 6 in total 3 programming questions, 8 marks each, 24 in total am/cpsc111B-Asg1-F23.docx Assigned: Wednesday Sep 27, 2023 Page 1/6 A. Multiple Choice Questions -0
1. What is the output of the following code? def paramTest(a, b): c = a + ' ' + b return c p0 = 'Pokemon' p1 = 'keldeo' c = paramTest(p0, p1) print(c) (a) ab (b) a b (c) Pokemonkeldeo (d) Pokemon keldeo 2. What is the output of the following python code? n,i,s = 6,1,0 while i < n: if i % 2 != 0: s += i i = i + 1 print(s) (a) 6 (b) 9 (c) -9 (d) Error 3. What is the output of the following python code? x = [5, 4, 3, 2, 1] for i in range(len(x) - 1): if x[i] > x[i+1]: x[i],x[i+1] = x[i+1],x[i] print(x) (a) [5, 3, 4, 1, 2] (b) [4, 3, 2, 1, 5] (c) [1, 2, 3, 4, 5] (d) Error 4. What is the output of the following python code? def Fun(a, b, c): if a % b == 0 and a % c == 0: return a elif a % b == 0: return b elif a % c == 0: return c else: return 0 print(Fun(12, 4, 13)) am/cpsc111B-Asg1-F23.docx Assigned: Wednesday Sep 27, 2023 Page 2/6 (a) 4 (b) 12 (c) 13 (d) Error
5. What is the output of the following code? number = 711 def modify(number): number = 7 return (number+4) print('number is', number) (a) number is 7 (b) number is 715 (c) number is 711 (d) None of the above. 6. What is the output of the following code? m = 100 while True: if m < 20: break m -= 19 print(m) (a) 19 (b) 5 (c) 1 (d) None of the above. 7. How many times is the print(“F”) statement executed in the following code? for m in "xyyzttttx": if m in "ztx": continue print("F") (a) 2 (b) 6 (c) 3 (d) None of the above. 8. What is the output of the following code? def checkMe(): x = "Cheers" print(x) print(x, "My Dear") print(x) checkMe() (a) Cheers (b) Cheers (c) Cheers My Dear (d) Error Cheers My Dear Cheers Cheers Cheers Cheers My Dear Cheers am/cpsc111B-Asg1-F23.docx Assigned: Wednesday Sep 27, 2023 Page 3/6 9. What is the output of print('ABcdBGCDGHcdH'.split('cd') )? (a) ['AB', 'BG',’GH’, 'H'] (b) ['AB', 'BGCDGH', 'H']
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help