cpsc111B-Asg1-Fall2023-Chiamaka Amanda Alumonah_10134234
.docx
keyboard_arrow_up
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
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
Related Questions
C PROGRAM / C LANGUAGEMake a C program array
arrow_forward
Requirements for Your M5 Assignment 1 Pseudocode for Program Integration
For the first module, write the pseudocode to process these tasks:(Note: lines beginning with # are comments with tips for you)
From the random module import randint to roll each die randomly
# in pseudocode, import a random function
# the name is helpful for the next M5-2 assignment
Define a class called Dice
In Python, the syntax has a colon after it: class Dice():
In pseudocode, you can specify it generally or be specific
Under the class declaration, list the attributes. Here are some tips:
# attributes are what we know about a single die (dice is plural)
# self is the first attribute in Python and must always appear first
# add a num_sides attribute and to set it to 6 for the 6 sides on the dice
Define a method for roll(self)
# it describes what happens when we roll a single die
# in the code, it will look like this example
def __init__(self, dice_sides=6):
# in pseudocode, we do not worry about…
arrow_forward
Find the bug in my simple python code and correct it. let me knwo if there are tab errors
# Course : ICT 4007: Creative Problem Solving and Programming Concepts
# Term : Fall 2021
# Program Name : Python Coding Project
# Author : Robel Geremew
# Date Written : 11/14/2021
# Description : This program demonstrates our understanding of classes, objects and arrays in python
# Declaring an employee class
class Employee:
def __init__(self, name):
self.name = name
def print_array (self,name):
emlpoyee = ["Homer" , "Lisa", "Marge", "Maggie", "Bart"]
for n in emlpoyee:
emlpoyee(n)
# Creating employee objects and accessing attributes
my_employee_1 = Employee("Homer")
print(" The first employee is " , my_employee_1.name)
my_employee_2 = Employee("Lisa")
print(" The Second employee is " , my_employee_2.name)
my_employee_3 = Employee("Marge")
print(" The Third employee is " ,…
arrow_forward
Use c++
arrow_forward
Python
learning object :
Function creation
Character multiplication (a * 5 == aaaaa)
Using len function
In the code I should also define __name__ == '__main__'
arrow_forward
Preferred language C++ or Java
arrow_forward
I need answer in C programming language
arrow_forward
8.
Build & Fix Model is suitable for programming exercises of ___________ LOC (Line of Code).
a.
100-200
b.
200-400
c.
400-1000
d.
above 1000
arrow_forward
Fill in the Gaps
Code in C language
arrow_forward
COMPUTER PROGRAMMING
arrow_forward
THIS NEEDS TO BE DONE IN C#!
Instructions
For your first task as a newly formed team of developers, you will design, develop, test, and deliver a small software application to a client. You will first take the requirements for the project and implement a UML and function design for each of the classes you need to create. This MUST be achieved first. You will need to read and understand the requirements and choose good classes that need to be created in the development phase of this project.
After you are finished with the design, you will use Visual Studio, C#, and GitHub to develop and test the project. Teams will need to determine who will write what parts of the system before development proceeds. Members will need to create branches to work in, which should be used to work in. Commits should be made often and contain details on changes made in the code. Once intended work for a branch is made, a pull request should be made to its parent branch to merge work. The team leader or…
arrow_forward
What is __init__() in Python?
arrow_forward
Ocelot/PuTTY(C Language)
Through this programming assignment, the students will learn to do the following:
Learn to work with command line options and arguments
Gain more experience with Makefiles
Gain more experience with Unix
Learn to use some of the available math funtions available with C
Usage: mortgagepmt [-s] -r rate [-d downpayment] price
In this assignment, you are asked to do a mortgage payment calculation. All information needed for this will be passed to the program on the command line. There will be no user input during the execution of the program.
You will need a few pieces of information. The price of the home and the amount of the down payment. You will also need to know the interest rate and the term of the mortgage. To figure your mortgage payment, start by converting your annual interest rate to a monthly interest rate by dividing by 12. Next, add 1 to the monthly rate. Third, multiply the number of years in the term of the mortgage by 12 to calculate the number…
arrow_forward
Create a C++ Grocery Program according to this guideline:
Linked List
Functions
Pointers
Arrays
The program must have a menu layout where the user can select certain action (Select Product, View My Cart, Check-Out, etc.)
Include grocery items (e.g. Fruits, Vegetables, Drinks, etc.)
Implement basic error tapping
Include the group name of the developers with the name of each developer (a total of 4)
arrow_forward
C++ Programming
Make a source code using C++ Programming only (Not java, not python, C++ ONLY)
16. Cody's Time Management
by CodeChum Admin
Cody’s celebrity status was enough for brand sponsorships from a wide spectrum of brands to come rushing in. Cody has to choose between hair products, pet groomers, gambling sites, and more. The Programmer warned Cody not to accept too much because Cody still has school after all, so they both decided to have a limit of 100 endorsements for Cody, beyond that number is simply too much even for a robot like him. Input the number of endorsements Cody is getting and print it. If it is above 100, print "That's a lot" below the number.
Input
1. Number of Cody's endorsements
Constraints
This is a positive integer.
Output
The first line will contain a message prompt to input the number of endorsements. The second line will contain the inputted number of endorsements and the message, "That's a lot" if it is.…
arrow_forward
Java Question 16:
arrow_forward
C programming task
Analyse pgmEcho.c to identify how it should be improved, then rewrite it so that it is more modular, more suitable for reuse, and properly defensive in terms of errors. Note that this should involve understanding the remaining tasks as well.
Code Below:
#include <stdio.h>
#include <stdlib.h>
#define EXIT_NO_ERRORS 0
#define EXIT_WRONG_ARG_COUNT 1
#define EXIT_BAD_INPUT_FILE 2
#define EXIT_BAD_OUTPUT_FILE 3
#define MAGIC_NUMBER_RAW_PGM 0x3550
#define MAGIC_NUMBER_ASCII_PGM 0x3250
#define MIN_IMAGE_DIMENSION 1
#define MAX_IMAGE_DIMENSION 65536
#define MAX_COMMENT_LINE_LENGTH 128
int main(int argc, char **argv)
{if (argc != 3)
{printf("Usage: %s input_file output_file\n", argv[0]);
return EXIT_WRONG_ARG_COUNT;
}
unsigned char magic_number[2] = {'0','0'};
unsigned short *magic_Number = (unsigned short *) magic_number;
char *commentLine = NULL;
unsigned int width = 0, height = 0;
unsigned int maxGray = 255;
unsigned char *imageData = NULL;
FILE *inputFile =…
arrow_forward
FUNCTIONS PROBLEM
Find and fix the errors ( in PYTHON)
#import math library
#define functions
#return type: float#Parameters: 2 floats(l and w)#This function returns the area of a rectangle with the given dimensionsdef RectangleArea(l,w):#return type: float#Parameters: 2 floats(l and w)#This function returns the perimeter of a rectangle with the given dimensionsdef RectanglePerimeter(l,w):#return type: float#Parameters: 1 floats(r)#This function returns the area of a circle with the given radiusdef CircleArea(r):#return type: float#Parameters: 1 floats(r)#This function returns the circumference of a circle with the given radiusdef CircleCircumference(r):#return type: None#Parameters: None#This function displays an introductiondef Intro():#return type: None#Parameters: 4 floats(rectArea, rectPer, circArea, circum)#This function displays the four values passed to itdef PrintInfo(rectArea, rectPer, circArea, circum ):
#return type: float#Parameters: None#This function prompts the user for…
arrow_forward
Write a C++ program using Object Ononted Programming (0OP) style to create a class for JK library management You are to specify correctly, what parameters of your class should be private, public or protected Your program may be structured with the following specification and tasks
1 Program must be able to identity the student, student library to book(s) borrowed, dates Borrowed and due date to return books
2 Programme must be able to get and print particular details of a student and their library records
3. Programme must be able to enrol new student information into the library database on request
arrow_forward
Fill in the Gaps
Code in C language
arrow_forward
in python use fuctional programming
arrow_forward
Solve only Required 1
arrow_forward
c++
We want to build an address book that is capable of storing name, address, Birthday, Email & phone number ofa person. Address book provides functionality in the form of a menu. The feature list includes:• Add – to add a new person record• Delete – to delete an existing person record by name• Search – to search a person record by name· Exit – to exit from application
arrow_forward
IT1815
Laboratory Exercise
Understanding Algorithm with Python
Objective:
At the end of the exercise, the students should be able to:
▪ Construct a Python script based on the given algorithms.
Software Requirement:
▪ Python 3.7 or higher
Procedure:
1. Study the following sample Python syntaxes:
Task Sample Syntax Remarks
Variable declaration x = 5 No need to indicate the
data type. Do not add
semi-colon.
Comment #This is a comment.
input(“Enter your name”)
User input name =
Convert string to int(x) Convert to compare or
int or float. float(x) compute values.
Convert int or float str(x) Convert if the output must
to string. show a number and a…
arrow_forward
This is an object oriented programming question
The code should be in C++ language
Create a class Student having a private data members S_ID, S_Name and S_CGPA. Now create a public member functions void getID(), void getName() and getCGPA() and finally to display all the data members, create a function void display().
In the main(), create an array of student class, size of the array should be taken from user at run time and call all the functions defined in the class.
Sample Output:
Student 1
Enter ID: 1
Enter Name: Ali
Enter CGPA: 2.5
Student 2
Enter ID: 2
Enter Name: Ahmed
Enter CGPA: 2.9
Student 3
Enter ID: 3
Enter Name: Zain
Enter CGPA: 3.4
Student 1 informationID: 1
Name: Ali
CGPA: 2.5
Student 2 information
ID: 2
Name: Ahmed
CGPA: 2.9
Student 3 information
ID: 3
Name: Zain
CGPA: 3.4
arrow_forward
using C# language
arrow_forward
#Python Program-related question. So need the answer in python expressions.
#Do not use the 'round' function. keep it simple
#use sep='' function when needed to close space between $ sign and amount
#Answer image of the program is attached which was answered by Bartleby but can't use it as we have not studied 'round' function yet.
COSC 1336 –Programming Fundamentals IProgram 4 – Decision StructuresThe owners of the Annan Supermarket would like to have a program that computes theweekly gross pay of their employees. The user will enter an employee’s ID number, thehourly rate of pay, and the number of hours worked for the week. In addition, AnnanSupermarkets would like the program to compute the employee’s net pay and overtimepay. Overtime hours, any hours over 40, are paid at 1.5 the regular hourly rate.Net pay is Gross minus deductions. Assume that deductions are made up of income tax(at 10.5% of gross if the gross exceeds $600.00) and a $25 parking charge.The output should look like…
arrow_forward
Code to _develop software using a regular expression module to process the following phone numbers.you are to extract the area code,trunk, number, and optionally an extension for each number. You may use the regular expression module in the language of your choice, please note that we covered the syntax for Perl 5 which is imitated by python 3, javascript, C++, and C#. Java, too. 800-555-1212 800 555 1212 800.555.1212 (800) 555-1212 1-800-555-1212 800-555-1212-1234 800-555-1212x1234 800-555-1212ext. 1234 1-(800) 555.1212 #1234 Reporting: Demonstrate your results by outputting the extracted information for each input number. Your report should be one page and it should be include a discussion of your use of the regular expression module..
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Related Questions
- C PROGRAM / C LANGUAGEMake a C program arrayarrow_forwardRequirements for Your M5 Assignment 1 Pseudocode for Program Integration For the first module, write the pseudocode to process these tasks:(Note: lines beginning with # are comments with tips for you) From the random module import randint to roll each die randomly # in pseudocode, import a random function # the name is helpful for the next M5-2 assignment Define a class called Dice In Python, the syntax has a colon after it: class Dice(): In pseudocode, you can specify it generally or be specific Under the class declaration, list the attributes. Here are some tips: # attributes are what we know about a single die (dice is plural) # self is the first attribute in Python and must always appear first # add a num_sides attribute and to set it to 6 for the 6 sides on the dice Define a method for roll(self) # it describes what happens when we roll a single die # in the code, it will look like this example def __init__(self, dice_sides=6): # in pseudocode, we do not worry about…arrow_forwardFind the bug in my simple python code and correct it. let me knwo if there are tab errors # Course : ICT 4007: Creative Problem Solving and Programming Concepts # Term : Fall 2021 # Program Name : Python Coding Project # Author : Robel Geremew # Date Written : 11/14/2021 # Description : This program demonstrates our understanding of classes, objects and arrays in python # Declaring an employee class class Employee: def __init__(self, name): self.name = name def print_array (self,name): emlpoyee = ["Homer" , "Lisa", "Marge", "Maggie", "Bart"] for n in emlpoyee: emlpoyee(n) # Creating employee objects and accessing attributes my_employee_1 = Employee("Homer") print(" The first employee is " , my_employee_1.name) my_employee_2 = Employee("Lisa") print(" The Second employee is " , my_employee_2.name) my_employee_3 = Employee("Marge") print(" The Third employee is " ,…arrow_forward
- COMPUTER PROGRAMMINGarrow_forwardTHIS NEEDS TO BE DONE IN C#! Instructions For your first task as a newly formed team of developers, you will design, develop, test, and deliver a small software application to a client. You will first take the requirements for the project and implement a UML and function design for each of the classes you need to create. This MUST be achieved first. You will need to read and understand the requirements and choose good classes that need to be created in the development phase of this project. After you are finished with the design, you will use Visual Studio, C#, and GitHub to develop and test the project. Teams will need to determine who will write what parts of the system before development proceeds. Members will need to create branches to work in, which should be used to work in. Commits should be made often and contain details on changes made in the code. Once intended work for a branch is made, a pull request should be made to its parent branch to merge work. The team leader or…arrow_forwardWhat is __init__() in Python?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr